-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetalThemeMenu.java
More file actions
45 lines (34 loc) · 1.05 KB
/
MetalThemeMenu.java
File metadata and controls
45 lines (34 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import javax.swing.plaf.metal.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class MetalThemeMenu extends JMenu implements ActionListener {
MetalTheme[] themes;
public MetalThemeMenu (String name, MetalTheme[] themeArray) {
super(name);
themes = themeArray;
ButtonGroup group = new ButtonGroup();
for (int i = 0; i < themes.length; i++) {
JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i].getName());
group.add(item);
add(item);
item.setActionCommand (i+"");
item.addActionListener (this);
if ( i == 0)
item.setSelected(true);
}
}
public void actionPerformed(ActionEvent e) {
String numStr = e.getActionCommand();
MetalTheme selectedTheme = themes [ Integer.parseInt (numStr) ];
MetalLookAndFeel.setCurrentTheme (selectedTheme);
try {
UIManager.setLookAndFeel ("javax.swing.plaf.metal.MetalLookAndFeel");
}
catch (Exception ex) {
System.out.println("Failed loading Metal");
System.out.println(ex);
}
}
}