private JMenuBar createMenuBar() { JMenu menu = new JMenu("Menu"); disablingItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.ALT_MASK)); menu.add(disablingItem); menu.addSeparator(); blurItem.setSelected(true); blurItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, InputEvent.ALT_MASK)); menu.add(blurItem); embossItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, InputEvent.ALT_MASK)); menu.add(embossItem); busyPainterItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, InputEvent.ALT_MASK)); menu.add(busyPainterItem); ButtonGroup group = new ButtonGroup(); group.add(blurItem); group.add(embossItem); group.add(busyPainterItem); ItemListener menuListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (blurItem.isSelected()) { // layer.setUI(blurUI); } else if (embossItem.isSelected()) { // layer.setUI(embossUI); } else if (busyPainterItem.isSelected()) { layer.setUI(busyPainterUI); } } }; blurItem.addItemListener(menuListener); embossItem.addItemListener(menuListener); busyPainterItem.addItemListener(menuListener); // embossUI.getUnlockButton().addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent e) { // disablingItem.doClick(); // } // }); JMenuBar bar = new JMenuBar(); bar.add(menu); bar.add(new LafMenu()); return bar; }
/** Creates a menu bar. */ protected JMenuBar createMenuBar() { JMenu fileMenu = new JMenu("File"); JMenuItem menuItem; menuItem = new JMenuItem("Open"); menuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { JFileChooser fc = new JFileChooser(path); int result = fc.showOpenDialog(frame); if (result == JFileChooser.APPROVE_OPTION) { String newPath = fc.getSelectedFile().getPath(); new ComponentTree(newPath); } } }); fileMenu.add(menuItem); fileMenu.addSeparator(); menuItem = new JMenuItem("Exit"); menuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { System.exit(0); } }); fileMenu.add(menuItem); // Create a menu bar JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); // Menu for the look and feels (lafs). UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels(); ButtonGroup lafGroup = new ButtonGroup(); JMenu optionsMenu = new JMenu("Options"); menuBar.add(optionsMenu); for (int i = 0; i < lafs.length; i++) { JRadioButtonMenuItem rb = new JRadioButtonMenuItem(lafs[i].getName()); optionsMenu.add(rb); rb.setSelected(UIManager.getLookAndFeel().getName().equals(lafs[i].getName())); rb.putClientProperty("UIKey", lafs[i]); rb.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ae) { JRadioButtonMenuItem rb2 = (JRadioButtonMenuItem) ae.getSource(); if (rb2.isSelected()) { UIManager.LookAndFeelInfo info = (UIManager.LookAndFeelInfo) rb2.getClientProperty("UIKey"); try { UIManager.setLookAndFeel(info.getClassName()); SwingUtilities.updateComponentTreeUI(frame); } catch (Exception e) { System.err.println("unable to set UI " + e.getMessage()); } } } }); lafGroup.add(rb); } return menuBar; }