嗨我有一個小菜單的Swing應用程序。 創建了包含menues文本的前兩個屬性,然後將lookandfeel設置爲windows,最後填充menues。 這裏是源代碼:JMenu沒有在Windows的外觀和感覺
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);
}
這就是醜陋的輸出:
爲什麼它看起來像這樣?
您是否嘗試過檢查異常而不是忽略它以確保l&f實際上已被更改:'catch(Exception x){System.out.println(「Could not change the look and feel」);}' – assylias 2012-03-15 12:30:10
你,但我已經檢查過它,並沒有例外。 – 2012-03-15 12:34:30
如果將'setLookAndFeel(...)'更改爲'setLookAndFeel(UIManager.getSystemLookAndFeelClassName())',那麼有什麼更改? – 2012-03-15 12:39:55