我的主对话框中的按钮变得如此困惑。我认为在对话框中添加一个带有一些按钮的工具栏会非常酷。
我当前正在使用应用程序工具栏中的图像来启动我的应用程序。它位于 Plugin.xml 代码中
icon="icons/ediOrb.png"
因此,在我的对话框中,我尝试为刷新按钮使用相同的图标
JToolBar toolbar = new JToolBar();
refreshButton = new JButton(new ImageIcon("icons/ediOrb.png"));
refreshButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
refreshTable();
}
});
toolbar.add(refreshButton);
centerPanel = new JPanel();
centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.PAGE_AXIS));
centerPanel.setPreferredSize(new Dimension(850, 450));
centerPanel.add(Box.createRigidArea(new Dimension(5, 0)));
centerPanel.add(currentPanel);
centerPanel.add(selectionsPanel);
centerPanel.add(Box.createHorizontalGlue());
centerPanel.add(Box.createRigidArea(new Dimension(0, 2)));
centerPanel.add(buttonPanel);
getContentPane().add(toolbar,BorderLayout.PAGE_START );
getContentPane().add(centerPanel);
没有显示该按钮的图像。它只显示了一个很小的点。它不会抛出任何错误,只是不显示图像。
有什么想法吗?
最佳答案
我也遇到了同样的问题。在 Netbeans 中我必须去:
Run | Set Project Configuration | customize --
然后添加包含我的项目和图标的工作目录路径。 我不确定如何在不同的 IDE 中执行此操作,但修复后我的图标出现了。
关于java - JToolBar - JButton - 图像未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11616760/