【发布时间】:2016-10-02 10:41:56
【问题描述】:
我用 JPanel 做了一个棋盘。使用 ImageIcon 不起作用,所以我查看了该站点,但所有这些似乎都很复杂,如何将图像添加到数组中,例如
tiles[0][0].setIcon(br);
这是我为棋盘创建的 JPanel
private JPanel[][] tiles = new JPanel[6][6];
我试过这个:
ImageIcon bn = new ImageIcon("art/BN.gif");
ImageIcon bb = new ImageIcon("art/BB.gif");
ImageIcon br = new ImageIcon("art/BR.gif");
ImageIcon wn = new ImageIcon("art/WN.gif");
ImageIcon wb = new ImageIcon("art/WB.gif");
ImageIcon wr = new ImageIcon("art/WR.gif");
tiles[0][0].add(new JLabel(bn));
tiles[0][1].add(new JLabel(wn));
tiles[0][2].add(new JLabel(wb));
tiles[0][3].add(new JLabel(wb));
tiles[0][4].add(new JLabel(wn));
tiles[0][5].add(new JLabel(wr));
tiles[5][0].add(new JLabel(br));
tiles[5][1].add(new JLabel(bn));
tiles[5][2].add(new JLabel(bb));
tiles[5][3].add(new JLabel(bb));
tiles[5][4].add(new JLabel(bn));
tiles[5][5].add(new JLabel(br));
但它不起作用
【问题讨论】:
-
你能看到面板吗?你能看到标签吗?有什么错误吗?
-
@Fast SnailCant 看不到标签
-
ambs 的回答对你有用吗?