【发布时间】:2013-12-11 20:36:40
【问题描述】:
我目前正在用 java 制作游戏,并且有一个带有图像图标的 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");尝试给出完整的图像路径
-
我添加了以下行:DiceIcon = new ImageIcon("src/Client/images/DiceIcon.png");这仍然行不通:(
-
尝试从项目中的开始文件获取路径,看看是否可行...在路径方面,图像很棘手
标签: java user-interface jbutton packaging imageicon