Mar*_*rdt 3 java swing look-and-feel
嗨,我有一个带菜单的Swing应用程序.创建包含menues文本的前两个属性,然后将lookandfeel设置为windows,最后填充menues.这是源代码:
private JMenu[] Menue={new JMenu("File")};
private JMenuItem[][] MenuItemsString ={{new JMenuItem("Import"),new JMenuItem("Export")}};
...
public window(){
       super ("Q3MeshConverter");
       plate = new JPanel(new BorderLayout());
       try{
           UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");// set Windows lookandfeel
           }
           catch(Exception x){
           }
       menuBar = new JMenuBar();
       ...
       setJMenuBar(menuBar);
       JMenu[] Menu =Menue;
       JMenuItem[][] MenuItems =MenuItemsString;
       for(int m=0;m<Menu.length;m++){// loop trough the Menu(es)
           menuBar.add(Menu[m]);
           for(int mi=0;mi<MenuItems[m].length;mi++){// loop through the MenuItems
               Menu[m].add(MenuItems[m][mi]);
               MenuItems[m][mi].addActionListener(this);
           }
       }
       ...   
       setContentPane (plate);
}
那是丑陋的输出:

它为什么会这样?
在LAF变更之前创建的组件如何知道它是没有神奇的,你必须告诉它:-)
SwingUtilities.updateComponentTreeUI(someComponent);