2014-04-13 50 views
1

对不起,这是非常基础的。我的第一次使用Eclipse的Java Swing体验。我试图写一个非常简单的JOptionPane。我想让问号图标出现,但我得到的只是Java咖啡杯图标。我究竟做错了什么?谢谢!JOptionPane上的图标

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

+1

你为什么不使用这一个,而不是http://docs.oracle.com/javase/6/docs/api/javax/swing/JOptionPane.html#showConfirmDialog%28java.awt.Component,% 20java.lang.Object,%20java.lang.String,%20int,%20int,%20javax.swing.Icon%29 ?? –

回答

2

请看看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

+0

完美。谢谢! – Alex

+0

没有。欢迎。 – Braj