【发布时间】:2014-03-25 00:34:24
【问题描述】:
我正在开发一个棋盘,但有一个问题。我正在尝试使用图像来表示棋盘。但是图像没有显示。
这是有问题的代码:
//Add a chess board to the 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);
for (int i = 0; i < 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") );
}
所有显示的都是碎片,没有正方形,在此先感谢。
【问题讨论】:
-
我不认为
"/Users/Downloads/pieces/EmptySquare.jpg"是真正的路径。没有驱动器? -
路径不是问题,我不得不编辑问题中的路径,因为它部分包含我的名字。
-
我知道,只是指出来。问题是您没有对
JLabel做任何事情。