当前位置: 首页>>代码示例>>Java>>正文


Java JMenuItem.setEnabled方法代码示例

本文整理汇总了Java中javax.swing.JMenuItem.setEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java JMenuItem.setEnabled方法的具体用法?Java JMenuItem.setEnabled怎么用?Java JMenuItem.setEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JMenuItem的用法示例。


在下文中一共展示了JMenuItem.setEnabled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildViewsMenu

import javax.swing.JMenuItem; //导入方法依赖的package包/类
protected JMenu buildViewsMenu() {
    JMenu views = new JMenu("Views");

    JMenuItem inBox = new JMenuItem("Open In-Box");
    JMenuItem outBox = new JMenuItem("Open Out-Box");
    outBox.setEnabled(false);

    inBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            openInBox();
        }
    });

    views.add(inBox);
    views.add(outBox);
    return views;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:MetalworksFrame.java

示例2: createDropdownItem

import javax.swing.JMenuItem; //导入方法依赖的package包/类
private static JMenuItem createDropdownItem(final Action action) {
    String name = (String)action.getValue("menuText"); // NOI18N
    if (name == null || name.trim().isEmpty()) name = (String)action.getValue(NAME);
    final JMenuItem item = new JMenuItem(Actions.cutAmpersand(name)) {
        public void fireActionPerformed(ActionEvent e) {
            action.actionPerformed(e);
        }
    };
    item.setEnabled(action.isEnabled());
    
    // #231371
    action.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            String propName = evt.getPropertyName();
            if ("enabled".equals(propName)) { // NOI18N
                item.setEnabled((Boolean)evt.getNewValue());
            } else if ("menuText".equals(propName)) { // NOI18N
                item.setText(Actions.cutAmpersand((String) evt.getNewValue()));
            }
        }
    });

    return item;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ProfilerToolbarDropdownAction.java

示例3: configureMenuItem

import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void configureMenuItem (JMenuItem item, String containerCtx, String action, ActionProvider provider, Map context) {
//        System.err.println("ConfigureMenuItem: " + containerCtx + "/" + action);
        item.setName(action);
        item.putClientProperty(KEY_ACTION, action);
        item.putClientProperty(KEY_CONTAINERCONTEXT, containerCtx);
        item.putClientProperty(KEY_CREATOR, this);
        item.setText(
            provider.getDisplayName(action, containerCtx));
        item.setToolTipText(provider.getDescription(action, containerCtx));
        int state = context == null ? ActionProvider.STATE_ENABLED | ActionProvider.STATE_VISIBLE :
            provider.getState (action, containerCtx, context);
        boolean enabled = (state & ActionProvider.STATE_ENABLED) != 0; 
        item.setEnabled(enabled);
        boolean visible = (state & ActionProvider.STATE_VISIBLE) != 0;
        //Intentionally use enabled property
        item.setVisible(enabled);
        item.setMnemonic(provider.getMnemonic(action, containerCtx));
        item.setDisplayedMnemonicIndex(provider.getMnemonicIndex(action, containerCtx));
        item.setIcon(provider.getIcon(action, containerCtx, BeanInfo.ICON_COLOR_16x16));
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:AbstractContextMenuFactory.java

示例4: createAnimationMenu

import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void createAnimationMenu() {
	animationMenu = new JMenu("Animation");
	animationMenu.setMnemonic(KeyEvent.VK_A);
	fileMenu.getAccessibleContext().setAccessibleDescription(
			"Manage the animation.");
	menuBar.add(animationMenu);
	animationMenu.setEnabled(false);

	initialiseItem = new JMenuItem("Initialise");
	initialiseItem.setMnemonic(KeyEvent.VK_I);
	initialiseItem.addActionListener(menuListener);
	animationMenu.add(initialiseItem);

	playPauseItem = new JMenuItem("Play");
	playPauseItem.setMnemonic(KeyEvent.VK_P);
	playPauseItem.addActionListener(menuListener);
	animationMenu.add(playPauseItem);

	stopItem = new JMenuItem("Stop");
	stopItem.setMnemonic(KeyEvent.VK_T);
	stopItem.addActionListener(menuListener);
	stopItem.setEnabled(false);
	animationMenu.add(stopItem);
}
 
开发者ID:moment-of-peace,项目名称:AI-RRT-Motion-Planning,代码行数:25,代码来源:Visualiser.java

示例5: propertyChange

import javax.swing.JMenuItem; //导入方法依赖的package包/类
@Override
public void propertyChange(PropertyChangeEvent evt) {
    JMenuItem item = itemRef.get();
    if (item == null) {
        return ;
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("Threads have changed: "+evt.getPropertyName()+": "+evt.getNewValue());
        logger.fine("item is showing: "+item.isShowing());
    }
    if (item.isShowing()) {
        item.setEnabled(ThreadsHistoryAction.getThreads().size() > 0);
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("  threads size = "+ThreadsHistoryAction.getThreads().size()+
                        " => item.isEnabled() = "+item.isEnabled());
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:SetCurrentThreadFromHistoryAction.java

示例6: synchMenuPresenters

import javax.swing.JMenuItem; //导入方法依赖的package包/类
@NbBundle.Messages({
    "LAB_ToolsActionInitializing=Initializing..."
})
@Override
public JComponent[] synchMenuPresenters(JComponent[] items) {
    G g = gl(50);
    if (g == null) {
        JMenuItem init = new JMenuItem();
        init.setText(Bundle.LAB_ToolsActionInitializing());
        init.setEnabled(false);
        return new JMenuItem[] { init };
    }
    if (timestamp == g.getTimestamp()) {
        return items;
    }
    // generate directly list of menu items
    List<JMenuItem> l = generate(toolsAction, true);
    timestamp = gl().getTimestamp();
    return l.toArray(new JMenuItem[l.size()]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ToolsAction.java

示例7: initMenu

import javax.swing.JMenuItem; //导入方法依赖的package包/类
void initMenu() {
	addLoc = new JMenuItem("Add Place");
	menu.add( addLoc );
	addLoc.addActionListener( this );
	loadLoc = new JMenuItem("Load Places");
	menu.add( loadLoc );
	loadLoc.addActionListener( this );
	editLoc = new JMenuItem("Edit Places");
	menu.add( editLoc );
	editLoc.addActionListener( this );
	editLoc.setEnabled(false);
	showLoc = new JCheckBoxMenuItem("Show Places", false);
	menu.add( showLoc );
	showLoc.addActionListener( this );
//	showLoc.setEnabled(false);
	menu.addSeparator();
	list = new JCheckBox("add to list", true);
	save = new JCheckBox("save to file", false);
	newSave = new JCheckBox("save to new file", false);
	addPresetLocations();
//	addMyLocations();
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:23,代码来源:MapLocations.java

示例8: createDisplayMenu

import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void createDisplayMenu() {
	displayMenu = new JMenu("Display");
	displayMenu.setMnemonic(KeyEvent.VK_D);
	fileMenu.getAccessibleContext().setAccessibleDescription(
			"Display the problem and solution.");
	menuBar.add(displayMenu);

	problemItem = new JMenuItem("Problem");
	problemItem.setMnemonic(KeyEvent.VK_P);
	problemItem.addActionListener(menuListener);
	problemItem.setEnabled(false);
	displayMenu.add(problemItem);

	solutionItem = new JMenuItem("Solution");
	solutionItem.setMnemonic(KeyEvent.VK_S);
	solutionItem.addActionListener(menuListener);
	solutionItem.setEnabled(false);
	displayMenu.add(solutionItem);
}
 
开发者ID:moment-of-peace,项目名称:AI-RRT-Motion-Planning,代码行数:20,代码来源:Visualiser.java

示例9: LazyMenu

import javax.swing.JMenuItem; //导入方法依赖的package包/类
@NbBundle.Messages("LBL_SubProjectPopupMenu_Initializing=Initializing...")
private LazyMenu(Node[] nodes) {
    super(LBL_OpenSubprojectsAction_Name());
    this.activatedNodes = nodes;
    JMenuItem item = new JMenuItem(Bundle.LBL_SubProjectPopupMenu_Initializing());
    item.setEnabled(false);
    add(item);
    RP.post(new Runnable() {
        @Override
        public void run() {
            getSubProjects();
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:OpenSubprojects.java

示例10: getToolbarPresenter

import javax.swing.JMenuItem; //导入方法依赖的package包/类
@Override
public Component getToolbarPresenter() {
   
        JPopupMenu menu = new JPopupMenu();
        JButton button = DropDownButtonFactory.createDropDownButton(
                new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), menu);
        final JMenuItem item = new JMenuItem(org.openide.awt.Actions.cutAmpersand((String) getValue("menuText")));
        item.setEnabled(isEnabled());

        addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                String propName = evt.getPropertyName();
                if ("enabled".equals(propName)) {
                    item.setEnabled((Boolean) evt.getNewValue());
                } else if ("menuText".equals(propName)) {
                    item.setText(org.openide.awt.Actions.cutAmpersand((String) evt.getNewValue()));
                }
            }
        });

        menu.add(item);
        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                MainProjectActionWithHistory.this.actionPerformed(e);
            }
        });
       
        org.openide.awt.Actions.connect(button, this);
        menu.addPopupMenuListener(this);
        return button;
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:MainProjectActionWithHistory.java

示例11: getPopupPresenter

import javax.swing.JMenuItem; //导入方法依赖的package包/类
@Override
@Messages({"ACT_Show=Show in POM", 
    "# {0} - artifactid of a project",
    "ACT_Current=Current: {0}",
    "# {0} - artifactid of a project",
    "ACT_PARENT=Parent: {0}"})
public JMenuItem getPopupPresenter() {
    JMenu menu = new JMenu();
    menu.setText(ACT_Show());
    POMCutHolder pch = node.getLookup().lookup(POMCutHolder.class);
    POMModel[] mdls = pch.getSource();
    Object[] val = pch.getCutValues();
    int index = 0;
    for (POMModel mdl : mdls) {
        String artifact = mdl.getProject().getArtifactId();
        JMenuItem item = new JMenuItem();
        item.setAction(new SelectAction(node, index));
        if (index == 0) {
            item.setText(ACT_Current(artifact != null ? artifact : "project"));
        } else {
            item.setText(ACT_PARENT(artifact != null ? artifact : "project"));
        }
        item.setEnabled(/* #199345 */index < val.length && val[index] != null);
        menu.add(item);
        index++;
    }
    return menu;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:POMModelVisitor.java

示例12: addGoodsAdditionEntry

import javax.swing.JMenuItem; //导入方法依赖的package包/类
/**
 * Add an "add goods" menu item to a unit menu.
 *
 * @param fcc The enclosing {@code FreeColClient}.
 * @param unit The {@code Unit} to add goods to.
 * @param menu The {@code JPopupMenu} to add the entry to.
 */
public static void addGoodsAdditionEntry(final FreeColClient fcc,
                                         final Unit unit, JPopupMenu menu) {
    JMenuItem addg = new JMenuItem("Add goods");
    addg.setOpaque(false);
    addg.addActionListener((ActionEvent ae) -> {
            DebugUtils.addUnitGoods(fcc, unit);
        });
    addg.setEnabled(true);
    menu.add(addg);
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:18,代码来源:DebugUtils.java

示例13: setMenu

import javax.swing.JMenuItem; //导入方法依赖的package包/类
/** Sets the state of JMenuItem*/
protected @Override void setMenu(){
    
    ActionMap am = getContextActionMap();
    Action action = null;
    if (am != null) {
        action = am.get(getActionName());
    }
    
    JMenuItem presenter = getMenuPresenter();
    Action presenterAction = presenter.getAction();
    if (presenterAction == null){
        presenter.setAction(this);
        presenter.setToolTipText(null); /* bugfix #62872 */ 
        menuInitialized = false;
    } 
    else {
        if (!this.equals(presenterAction)){
            presenter.setAction(this);
            presenter.setToolTipText(null); /* bugfix #62872 */
            menuInitialized = false;
        }
    }

    if (!menuInitialized){
        Mnemonics.setLocalizedText(presenter, getMenuItemText());
        menuInitialized = true;
    }

    presenter.setEnabled(action != null);
    JTextComponent comp = Utilities.getFocusedComponent();
    if (comp != null && comp instanceof JEditorPane){
        addAccelerators(this, presenter, comp);
    } else {
        presenter.setAccelerator(getDefaultAccelerator());
    }

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:CompletionActionsMainMenu.java

示例14: menuItem

import javax.swing.JMenuItem; //导入方法依赖的package包/类
/**
 * Construct a new JMenuItem then add it to an existing JMenu.
 * 
 * @param parent - the JMenu to add this JMenuItem into (or null if you
 *            don't want to add it to any JMenu yet)
 * @param label - the text to show on the menu
 * @param attrs - a list of attributes to apply onto the new JMenuItem
 *            <p>
 *            If one positive number a is supplied, we call setMnemonic(a)
 *            <p>
 *            If two positive numbers a and b are supplied, and a!=VK_ALT,
 *            and a!=VK_SHIFT, we call setMnemoic(a) and setAccelerator(b)
 *            <p>
 *            If two positive numbers a and b are supplied, and a==VK_ALT or
 *            a==VK_SHIFT, we call setAccelerator(a | b)
 *            <p>
 *            If an ActionListener is supplied, we call addActionListener(x)
 *            <p>
 *            If an Boolean x is supplied, we call setEnabled(x)
 *            <p>
 *            If an Icon x is supplied, we call setIcon(x)
 */
public static JMenuItem menuItem(JMenu parent, String label, Object... attrs) {
	JMenuItem m = new JMenuItem(label, null);
	int accelMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
	boolean hasMnemonic = false;
	for (Object x : attrs) {
		if (x instanceof Character || x instanceof Integer) {
			int k = (x instanceof Character) ? ((int) ((Character) x)) : ((Integer) x).intValue();
			if (k < 0)
				continue;
			if (k == KeyEvent.VK_ALT) {
				hasMnemonic = true;
				accelMask = accelMask | InputEvent.ALT_MASK;
				continue;
			}
			if (k == KeyEvent.VK_SHIFT) {
				hasMnemonic = true;
				accelMask = accelMask | InputEvent.SHIFT_MASK;
				continue;
			}
			if (!hasMnemonic) {
				m.setMnemonic(k);
				hasMnemonic = true;
			} else
				m.setAccelerator(KeyStroke.getKeyStroke(k, accelMask));
		}
		if (x instanceof ActionListener)
			m.addActionListener((ActionListener) x);
		if (x instanceof Icon)
			m.setIcon((Icon) x);
		if (x instanceof Boolean)
			m.setEnabled((Boolean) x);
	}
	if (parent != null)
		parent.add(m);
	return m;
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:59,代码来源:OurUtil.java

示例15: fillSubmenu

import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void fillSubmenu(JPopupMenu pop) {
    if (lastPopup == null) {
        pop.addPopupMenuListener(this);
        lastPopup = pop;

        removeAll();

        Iterator it = generate(toolsAction, false).iterator();

        while (it.hasNext()) {
            java.awt.Component item = (java.awt.Component) it.next();

            if (item == null) {
                addSeparator();
            } else {
                add(item);
            }
        }

        // also work with empty element
        if (getMenuComponentCount() == 0) {
            JMenuItem empty = new JMenuItem(NbBundle.getMessage(ToolsAction.class, "CTL_EmptySubMenu"));
            empty.setEnabled(false);
            add(empty);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:ToolsAction.java


注:本文中的javax.swing.JMenuItem.setEnabled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。