【问题标题】:Icons on JOptionPaneJOptionPane 上的图标
【发布时间】:2014-04-13 17:31:41
【问题描述】:

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

【问题讨论】:

标签: java swing icons joptionpane


【解决方案1】:

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

不同的主题:

【讨论】:

    猜你喜欢
    • 2014-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 2012-06-22
    相关资源
    最近更新 更多