我目前正在用java制作游戏并且有一个JButton,它有一个图像图标。唯一的问题是没有显示图像,甚至在调试窗口中也没有发生错误。JButton上没有显示图像图标
我打包了我的程序(请参阅屏幕截图 - https://db.tt/N9CwHJdf)。我使用的代码写在下面,如果有人能解决这个问题,我会非常感激。谢谢。
//Button Image
ImageIcon diceIcon = new ImageIcon("Client/images/DiceIcon.png");
//Create Button
JButton rollDice = new JButton("Roll Dice", diceIcon);
rollDice.setForeground(Color.darkGray);
rollDice.setFocusPainted(false);
rollDice.setPreferredSize(new Dimension(284,50));
rollDice.setBorder(BorderFactory.createLineBorder(Color.orange));
rollDice.setBackground(Color.orange);
rollDice.setToolTipText("Click to roll dice and continue playing");
rollDice.addActionListener(this);
DiceIcon = new ImageIcon(“Client/images/DiceIcon.png”);尝试给出完整的图像路径 – user2277872
我已经添加了以下行:DiceIcon = new ImageIcon(“src/Client/images/DiceIcon.png”);并仍然不起作用:( –
尝试从您的项目中的开始文件获取路径,并查看是否有效...图像是棘手的当涉及到路径 – user2277872