Reputation: 581
Hi I've got a little Swing Application with a Menu. First two attributes containing the menues text are created, then the lookandfeel is set to windows and at last the menues are filled. Here is the source code:
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);
}
And that's the ugly output:
Why does it looks like this?
Upvotes: 3
Views: 2602
Reputation: 4597
Set the look and feel in your main
method:
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) { }
}
Upvotes: 4
Reputation: 51536
There is no magic how a component created before the LAF change can know about it, you have to tell it :-)
SwingUtilities.updateComponentTreeUI(someComponent);
Upvotes: 8