當前位置: 首頁>>代碼示例>>Java>>正文


Java JMenuItem類代碼示例

本文整理匯總了Java中javax.swing.JMenuItem的典型用法代碼示例。如果您正苦於以下問題:Java JMenuItem類的具體用法?Java JMenuItem怎麽用?Java JMenuItem使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JMenuItem類屬於javax.swing包,在下文中一共展示了JMenuItem類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import javax.swing.JMenuItem; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(() -> {

        JPopupMenu popup = new JPopupMenu("Popup Menu");
        JMenu menu = new JMenu("Menu");
        menu.add(new JMenuItem("Menu Item"));
        popup.add(menu);
        menu.doClick();
        MenuElement[] elems = MenuSelectionManager
                .defaultManager().getSelectedPath();

        if (elems == null || elems.length == 0) {
            throw new RuntimeException("Empty Selection");
        }

        if (elems[0] != popup || elems[1] != menu) {
            throw new RuntimeException("Necessary menus are not selected!");
        }
    });
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:JPopupMenuEndlessLoopTest.java

示例2: getIconLeft

import javax.swing.JMenuItem; //導入依賴的package包/類
private static int getIconLeft(JMenuItem item) {
    if(Utilities.isWindows()) {
        if(isVista()) {
            return 1;
        }
        if(hasRadioOrCheckSibling(item)) {
            return 20;
        } else {
            return 20;
        }
    }
    
    if(isAqua()) {
        if(item instanceof JRadioButtonMenuItem) {
            return 11;
        }
        return 14;
    }
    
    //metal or other (hopefully) basic derived L&Fs
    if(isRadioOrCheck(item)) {
        return 20;
    }
    return 10;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:DropTargetLayer.java

示例3: createArrowButton

import javax.swing.JMenuItem; //導入依賴的package包/類
private JButton createArrowButton() {
    arrowMenu = new JPopupMenu();
    JButton button = DropDownButtonFactory.createDropDownButton(
        ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debuggingView/unvisited_bpkt_arrow_small_16.png", false), arrowMenu);
    button.setPreferredSize(new Dimension(40, button.getPreferredSize().height)); // [TODO]
    button.setMaximumSize(new Dimension(40, button.getPreferredSize().height)); // [TODO]
    button.setFocusable(false);
    button.setOpaque(false);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (arrowMenu.getComponentCount() > 0) {
                Object item = arrowMenu.getComponent(0);
                for (Map.Entry<DVThread, JMenuItem> entry : threadToMenuItem.entrySet()) {
                    if (entry.getValue() == item) {
                        debuggingView.makeThreadCurrent(entry.getKey());
                    } // if
                } // for
            } // if
        } // actionPerformed
    });
    return button;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:InfoPanel.java

示例4: updateState

import javax.swing.JMenuItem; //導入依賴的package包/類
/** @param changedProperty the name of property that has changed
* or null if it is not known
*/
@Override
public void updateState(String changedProperty) {
    super.updateState(changedProperty);

    if ((changedProperty == null) || !changedProperty.equals(Action.ACCELERATOR_KEY)) {
        updateKey((JMenuItem) comp, action);
    }

    if ((changedProperty == null) || changedProperty.equals(Action.NAME)) {
        Object s = action.getValue(Action.NAME);

        if (s instanceof String) {
            setMenuText(((JMenuItem) comp), (String) s, true);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:Actions.java

示例5: getPopupMenuItem

import javax.swing.JMenuItem; //導入依賴的package包/類
public JMenuItem getPopupMenuItem(JTextComponent target) {
    
    item = new JCheckBoxMenuItem(NbBundle.getBundle(BaseKit.class).
            getString("line-numbers-menuitem"), isLineNumbersVisible());
    item.addItemListener( new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            actionPerformed(null,null);
        }
    });
    return item;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:ActionFactory.java

示例6: visitMenuBar

import javax.swing.JMenuItem; //導入依賴的package包/類
/** Open all menus in menubar
 * @param menu  to be visited */
public static void visitMenuBar(JMenuBar menu) {
    MenuElement[] elements = menu.getSubElements();

    JMenuBarOperator op = new JMenuBarOperator(menu);

    for (int k = 0; k < elements.length; k++) {
        if (elements[k] instanceof JMenuItem) {
            op.pushMenu(((JMenuItem) elements[k]).getText(), "/", true, true);
            try {
                op.wait(200);
            } catch (Exception e) {
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:MenuChecker.java

示例7: addPayArrears

import javax.swing.JMenuItem; //導入依賴的package包/類
/**
 * Add an item to pay arrears on the given goods type.
 *
 * @param goodsType The {@code GoodsType} to pay arrears on.
 */
private void addPayArrears(final GoodsType goodsType) {
    final InGameController igc = freeColClient.getInGameController();

    JMenuItem menuItem = Utility.localizedMenuItem("payArrears");
    menuItem.addActionListener((ActionEvent ae) -> {
            igc.payArrears(goodsType);
            // FIXME: fix pcls so this hackery can go away
            if (parentPanel instanceof CargoPanel) {
                CargoPanel cargoPanel = (CargoPanel) parentPanel;
                cargoPanel.initialize();
            }
            parentPanel.revalidate();
        });
    this.add(menuItem);
}
 
開發者ID:wintertime,項目名稱:FreeCol,代碼行數:21,代碼來源:QuickActionMenu.java

示例8: PopuleBarra

import javax.swing.JMenuItem; //導入依賴的package包/類
public void PopuleBarra(JMenu obj) {
    int i = 0;
    for (ConfigAcao ca : Lista) {
        if (ca.tipo == TipoConfigAcao.tpMenuBarra || ca.tipo == TipoConfigAcao.tpAny) {
            Acao ac = new Acao(editor, ca.texto, ca.ico, ca.descricao, ca.command);
            ac.IDX = i++;
            JMenuItem mi = new JMenuItem(ac);
            //obj.add(mi);
            listaMenus.put(ca.command, mi);
            //ListaDeAcoes.add(ac);
        }
    }
    obj.setText(Editor.fromConfiguracao.getValor("Controler.interface.menu.menuDiagrama.texto"));
    char b = Editor.fromConfiguracao.getValor("Controler.interface.menu.menuDiagrama.mtecla").charAt(0);
    obj.setMnemonic(b);
    BarraMenu = obj;
}
 
開發者ID:chcandido,項目名稱:brModelo,代碼行數:18,代碼來源:Controler.java

示例9: createAndShowGUI

import javax.swing.JMenuItem; //導入依賴的package包/類
private static void createAndShowGUI(TestItem testItem) {

        frame = new JFrame();
        frame.setSize(300, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JMenuBar menuBar = new JMenuBar();
        menu = new JMenu("Menu");
        JMenuItem menuItem = testItem.getMenuItem();
        testItem.setProperties(menuItem);
        menu.add(menuItem);
        menuBar.add(menu);

        frame.setJMenuBar(menuBar);
        frame.setVisible(true);
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:CloseOnMouseClickPropertyTest.java

示例10: getPopupPresenter

import javax.swing.JMenuItem; //導入依賴的package包/類
@Override
public JMenuItem getPopupPresenter() {
    JMenu menu = createMenu();
    menu.setText(Bundle.CTL_MenuItem_IgnoreMenu_popupName());
    enableMenu(menu);
    return menu;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,代碼來源:IgnoreMenu.java

示例11: init

import javax.swing.JMenuItem; //導入依賴的package包/類
@PostConstruct
public void init() {
   	if (isInit) {
   		return;
   	}

   	isInit = true;

   	saveStream = new JMenuItem("Save ...", KeyEvent.VK_S);
   	saveStream.addActionListener(e -> saveFile());

   	add(saveStream);
}
 
開發者ID:kiwiwings,項目名稱:poi-visualizer,代碼行數:14,代碼來源:POIContextMenu.java

示例12: ClipboardActionsPopup

import javax.swing.JMenuItem; //導入依賴的package包/類
public ClipboardActionsPopup(JTextComponent parent) {
	this.parent = parent;

	this.cutMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.cut",
			new javax.swing.text.DefaultEditorKit.CutAction()));
	this.copyMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.copy",
			new javax.swing.text.DefaultEditorKit.CopyAction()));
	this.pasteMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.paste",
			new javax.swing.text.DefaultEditorKit.PasteAction()));
	this.deleteMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.delete",
			new TextActions.DeleteTextAction()));

	// this.clearMenuItem = new JMenuItem(new TextActions.ClearAction());

	this.selectAllMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.select_all",
			new TextActions.SelectAllAction()));

	this.add(this.cutMenuItem);
	this.add(this.copyMenuItem);
	this.add(this.pasteMenuItem);
	this.add(this.deleteMenuItem);
	this.addSeparator();
	// this.add(this.clearMenuItem);
	this.add(this.selectAllMenuItem);

	// this.setPreferredSize(new Dimension((int) this.getPreferredSize().getWidth() + 30, (int)
	// this.getPreferredSize().getHeight()));
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:29,代碼來源:ClipboardActionsPopup.java

示例13: getMenuPresenter

import javax.swing.JMenuItem; //導入依賴的package包/類
@Override
public JMenuItem getMenuPresenter() {
    JMenu menu = createMenu();
    org.openide.awt.Mnemonics.setLocalizedText(menu, menu.getText());
    enableMenu(menu);
    return menu;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,代碼來源:DynamicMenu.java

示例14: createMenu

import javax.swing.JMenuItem; //導入依賴的package包/類
protected JMenuItem createMenu(String title, int key, int modifier)
{
    JMenuItem item = new JMenuItem(title);
    if (key != 0) item.setAccelerator(KeyStroke.getKeyStroke(key, modifier));
    item.addActionListener(this);
    return item;
}
 
開發者ID:drytoastman,項目名稱:scorekeeperfrontend,代碼行數:8,代碼來源:ProSoloInterface.java

示例15: addMenuItems

import javax.swing.JMenuItem; //導入依賴的package包/類
private void addMenuItems(JMenu f, String m[]) {

        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

        for (int i = 0; i < m.length; i++) {
            if (m[i].equals("--")) {
                f.addSeparator();
            } else if (m[i].equals("---")) {

                // (ulrivo): full size on screen with less than 640 width
                if (d.width >= 640) {
                    f.addSeparator();
                } else {
                    return;
                }
            } else {
                JMenuItem item = new JMenuItem(m[i].substring(1));
                char      c    = m[i].charAt(0);

                if (c != '-') {
                    KeyStroke key =
                        KeyStroke.getKeyStroke(c, Event.CTRL_MASK);

                    item.setAccelerator(key);
                }

                item.addActionListener(this);
                f.add(item);
            }
        }
    }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:32,代碼來源:DatabaseManagerSwing.java


注:本文中的javax.swing.JMenuItem類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。