1 36 37 40 41 42 import javax.swing.plaf.metal.*; 43 import javax.swing.*; 44 import javax.swing.border.*; 45 import java.awt.*; 46 import java.awt.event.*; 47 48 54 public class MetalThemeMenu extends JMenu implements ActionListener{ 55 56 MetalTheme[] themes; 57 public MetalThemeMenu(String name, MetalTheme[] themeArray) { 58 super(name); 59 themes = themeArray; 60 ButtonGroup group = new ButtonGroup(); 61 for (int i = 0; i < themes.length; i++) { 62 JRadioButtonMenuItem item = new JRadioButtonMenuItem( themes[i].getName() ); 63 group.add(item); 64 add( item ); 65 item.setActionCommand(i+""); 66 item.addActionListener(this); 67 if ( i == 0) 68 item.setSelected(true); 69 } 70 71 } 72 73 public void actionPerformed(ActionEvent e) { 74 String numStr = e.getActionCommand(); 75 MetalTheme selectedTheme = themes[ Integer.parseInt(numStr) ]; 76 MetalLookAndFeel.setCurrentTheme(selectedTheme); 77 try { 78 UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); 79 } catch (Exception ex) { 80 System.out.println("Failed loading Metal"); 81 System.out.println(ex); 82 } 83 84 } 85 86 } 87 | Popular Tags |