swing - Java chess board image not showing -
i'm in process of developing chessboard, issue. i'm trying use image represent chess square. image isn't showing.
this code in question:
//add chess board layered pane chessboard = new jpanel(); layeredpane.add(chessboard, jlayeredpane.default_layer); chessboard.setlayout( new gridlayout(8, 8) ); chessboard.setpreferredsize( boardsize ); chessboard.setbounds(0, 0, boardsize.width, boardsize.height); (int = 0; < 64; i++) { jpanel square = new jpanel( new borderlayout() ); chessboard.add( square ); int row = (i / 8) % 2; if (row == 0); jlabel panel = new jlabel(new imageicon("/users/downloads/pieces/emptysquare.jpg") ); } all that's being shown pieces , no squares, in advance.
two things...
first...
your if statement ending in ;
if (row == 0); this ignoring statement altogether.
second, never seem add panel ui...
//... jlabel panel = new jlabel(new imageicon("/users/downloads/pieces/emptysquare.jpg") ); } // end of for-loop... consider using imageio.read instead of imageicon provide more details if image can't loaded. take @ reading/loading image more details...
Comments
Post a Comment