java - JOptionPane 上的图标

标签 java swing icons joptionpane

抱歉,这真的很基本。我第一次使用 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

enter image description here

最佳答案

请查看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
        }
    });

具有不同的主题:

enter image description here enter image description here enter image description here

关于java - JOptionPane 上的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23045956/

相关文章:

java - 在 Objective-C 中处理 "final"参数的适当方式

java - 如何编写具有渐进状态的 JUnit 测试

jquery - 更改图标图像的CSS代码

java - 在 JFrame 中显示图像

java - 解析 HTML - 仅获取表行的子集

java - 在java中使用多线程?

java - 将 "On Change"监听器放在 jFormattedTextField 上

java - Jfreechart:显示多个图表

crash - 尝试向工具栏添加图标会使OpenOffice Writer崩溃

java - 无法从 Tomcat 应用程序中的挂载点下载文件