抱歉,这真的很基本。我第一次使用 Eclipse 体验 Java Swing。我正在尝试编写一个非常简单的JOptionPane
。我希望显示问号图标,但我得到的只是 Java 咖啡杯图标。我究竟做错了什么?谢谢!
Object[] options = {"Encrypt", "Decrypt"};
int n = JOptionPane.showOptionDialog(new JFrame(),
"What Do You Want to Do?",
"Crypto",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, //do not use a custom Icon
options, //the titles of buttons
options[0]); //default button title
最佳答案
请查看How to Set the Look and Feel
尝试不同的主题
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
// Set Motif L&F on any platform
// UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
// Set cross-platform Java L&F (also called "Metal")
// UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
// Set System L&F
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
} catch (InstantiationException ex) {
} catch (IllegalAccessException ex) {
} catch (UnsupportedLookAndFeelException ex) {
}
Object[] options = { "Encrypt", "Decrypt" };
JOptionPane.showOptionDialog(new JFrame(), "What Do You Want to Do?", "Crypto",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a
// custom Icon
options, // the titles of buttons
options[0]); // default button title
}
});
具有不同的主题:
关于java - JOptionPane 上的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23045956/