コード例 #1
0
  private void buildMenu() {
    fooMenu = new JMenu("File");
    fooMenu.setMnemonic('F');

    JMenuItem aboutItem = new JMenuItem("About...");
    aboutItem.setMnemonic('A');
    aboutItem.setEnabled(true);
    aboutItem.setIcon(new ImageIcon(this.getClass().getResource("/comment.png")));
    aboutItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JLabel imageLabel =
                new JLabel(new ImageIcon(this.getClass().getResource("/solve_all_problems.gif")));
            JOptionPane.showMessageDialog(null, imageLabel, "About", JOptionPane.PLAIN_MESSAGE);
          }
        });

    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.setMnemonic('x');
    exitItem.setEnabled(true);
    exitItem.setIcon(new ImageIcon(this.getClass().getResource("/delete.png")));
    exitItem.addActionListener(this);

    fooMenu.add(aboutItem);
    fooMenu.addSeparator();
    fooMenu.add(exitItem);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fooMenu);
    setJMenuBar(menuBar);
  }
コード例 #2
0
 /**
  * This is the hook through which all menu items are created. It registers the result with the
  * menuitem hashtable so that it can be fetched with getMenuItem().
  *
  * @see #getMenuItem
  */
 protected JMenuItem createMenuItem(String cmd) {
   JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
   URL url = getResource(cmd + imageSuffix);
   if (url != null) {
     mi.setHorizontalTextPosition(JButton.RIGHT);
     mi.setIcon(new ImageIcon(url));
   }
   String astr = getResourceString(cmd + actionSuffix);
   if (astr == null) {
     astr = cmd;
   }
   mi.setActionCommand(astr);
   Action myaction = getAction(astr); // if this is a known action
   if (myaction != null) {
     mi.addActionListener(myaction);
     myaction.addPropertyChangeListener(createActionChangeListener(mi));
     // System.out.println("myaction not null: astr:"+astr+" enabled:"+myaction.isEnabled());
     mi.setEnabled(myaction.isEnabled());
   } else {
     System.err.println("Error:TextViewer: createMenuItem: myaction is null: astr:" + astr);
     // causes the item to be greyed out
     mi.setEnabled(false);
   }
   menuItems.put(cmd, mi);
   return mi;
 }
コード例 #3
0
  /*
   * Implements PopupMenuListener#popupMenuWillBecomeVisible(PopupMenuEvent).
   */
  public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    createOtrContactMenus(currentContact);

    JMenu menu = getMenu();

    menu.addSeparator();

    whatsThis = new JMenuItem();
    whatsThis.setIcon(OtrActivator.resourceService.getImage("plugin.otr.HELP_ICON_15x15"));
    whatsThis.setText(OtrActivator.resourceService.getI18NString("plugin.otr.menu.WHATS_THIS"));
    whatsThis.addActionListener(this);
    menu.add(whatsThis);
  }
コード例 #4
0
ファイル: Menus.java プロジェクト: haomen/refs
 public static JMenuItem createMenuItem(Object[] data) {
   JMenuItem m = null;
   MType type = (MType) data[1];
   if (type == mi) m = new JMenuItem();
   else if (type == cb) m = new JCheckBoxMenuItem();
   else if (type == rb) {
     m = new JRadioButtonMenuItem();
     bgroup.add(m);
   }
   m.setText((String) data[0]);
   m.setMnemonic(((Character) data[2]).charValue());
   m.addActionListener((ActionListener) data[3]);
   m.setEnabled(((Boolean) data[4]).booleanValue());
   if (data.length == 6) m.setIcon((Icon) data[5]);
   return m;
 }
コード例 #5
0
ファイル: Notepad.java プロジェクト: ArcherSys/ArcherSysRuby
 /** This is the hook through which all menu items are created. */
 protected JMenuItem createMenuItem(String cmd) {
   JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
   URL url = getResource(cmd + imageSuffix);
   if (url != null) {
     mi.setHorizontalTextPosition(JButton.RIGHT);
     mi.setIcon(new ImageIcon(url));
   }
   String astr = getProperty(cmd + actionSuffix);
   if (astr == null) {
     astr = cmd;
   }
   mi.setActionCommand(astr);
   Action a = getAction(astr);
   if (a != null) {
     mi.addActionListener(a);
     a.addPropertyChangeListener(createActionChangeListener(mi));
     mi.setEnabled(a.isEnabled());
   } else {
     mi.setEnabled(false);
   }
   return mi;
 }