forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickChange.java
More file actions
71 lines (63 loc) · 2.13 KB
/
Copy pathQuickChange.java
File metadata and controls
71 lines (63 loc) · 2.13 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//file: QuickChange.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class QuickChange extends JFrame {
public QuickChange() {
super("QuickChange v1.0");
createGUI();
}
protected void createGUI( ) {
setSize(300, 200);
// create a simple File menu
JMenu file = new JMenu("File", true);
JMenuItem quit = new JMenuItem("Quit");
file.add(quit);
quit.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent e) { System.exit(0); }
});
// create the Look & Feel menu
JMenu lnf = new JMenu("Look & Feel", true);
ButtonGroup buttonGroup = new ButtonGroup( );
final UIManager.LookAndFeelInfo[] info =
UIManager.getInstalledLookAndFeels( );
for (int i = 0; i < info.length; i++) {
JRadioButtonMenuItem item = new
JRadioButtonMenuItem(info[i].getName( ), i == 0);
final String className = info[i].getClassName( );
item.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent ae) {
try { UIManager.setLookAndFeel(className); }
catch (Exception e) { System.out.println(e); }
SwingUtilities.updateComponentTreeUI(QuickChange.this);
}
});
buttonGroup.add(item);
lnf.add(item);
}
// add the menu bar
JMenuBar mb = new JMenuBar( );
mb.add(file);
mb.add(lnf);
setJMenuBar(mb);
// add some components
JPanel jp = new JPanel( );
jp.add(new JCheckBox("JCheckBox"));
String[] names =
new String[] { "Tosca", "Cavaradossi", "Scarpia",
"Angelotti", "Spoletta", "Sciarrone",
"Carceriere", "Il sagrestano", "Un pastore" };
jp.add(new JComboBox(names));
jp.add(new JButton("JButton"));
jp.add(new JLabel("JLabel"));
jp.add(new JTextField("JTextField"));
JPanel main = new JPanel(new GridLayout(1, 2));
main.add(jp);
main.add(new JScrollPane(new JList(names)));
setContentPane(main);
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
public static void main(String[] args) {
new QuickChange().setVisible(true);
}
}