01: package test;
02:
03: import java.awt.*;
04:
05: import javax.swing.*;
06:
07: import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
08:
09: public class TestMenu extends JFrame {
10: TestMenu() {
11: JMenuBar jmb = new JMenuBar();
12: JMenu menu = new JMenu("menu");
13: menu.add(new JMenuItem("item1", new Icon() {
14: public int getIconHeight() {
15: return 16;
16: }
17:
18: public int getIconWidth() {
19: return 16;
20: }
21:
22: public void paintIcon(Component c, Graphics g, int x, int y) {
23: Graphics2D g2 = (Graphics2D) g.create();
24: g2.setColor(Color.red);
25: g2.fillRect(x, y, 15, 15);
26: g2.dispose();
27: }
28: }));
29: menu.add(new JCheckBoxMenuItem("item2", new Icon() {
30: public int getIconHeight() {
31: return 8;
32: }
33:
34: public int getIconWidth() {
35: return 8;
36: }
37:
38: public void paintIcon(Component c, Graphics g, int x, int y) {
39: Graphics2D g2 = (Graphics2D) g.create();
40: g2.setColor(Color.red);
41: g2.fillRect(x, y, 7, 7);
42: g2.dispose();
43: }
44: }));
45: JRadioButtonMenuItem menuItem3 = new JRadioButtonMenuItem(
46: "item3");
47: menuItem3.setSelected(true);
48: menu.add(menuItem3);
49: jmb.add(menu);
50:
51: this .setJMenuBar(jmb);
52:
53: this .setSize(200, 200);
54: this .setLocationRelativeTo(null);
55: this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
56: }
57:
58: public static void main(String[] args) throws Exception {
59: UIManager.setLookAndFeel(new WindowsLookAndFeel());
60: SwingUtilities.invokeLater(new Runnable() {
61: public void run() {
62: new TestMenu().setVisible(true);
63: }
64: });
65: }
66: }
|