Java Code Examples for javax.swing.JMenuItem#isEnabled()

The following examples show how to use javax.swing.JMenuItem#isEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultAWTBridge.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override Component[] convertComponents(Component comp) {
    if (comp instanceof JMenuItem) {
        JMenuItem item = (JMenuItem) comp;
        if (Boolean.TRUE.equals(item.getClientProperty(DynamicMenuContent.HIDE_WHEN_DISABLED)) && !item.isEnabled()) {
            return new Component[0];
        }
    }
     if (comp instanceof DynamicMenuContent) {
        Component[] toRet = ((DynamicMenuContent)comp).getMenuPresenters();
        boolean atLeastOne = false;
        Collection<Component> col = new ArrayList<Component>();
        for (int i = 0; i < toRet.length; i++) {
            if (toRet[i] instanceof DynamicMenuContent && toRet[i] != comp) {
                col.addAll(Arrays.asList(convertComponents(toRet[i])));
                atLeastOne = true;
            } else {
                if (toRet[i] == null) {
                    toRet[i] = new JSeparator();
                }
                col.add(toRet[i]);
            }
        }
        if (atLeastOne) {
            return col.toArray(new Component[col.size()]);
        } else {
            return toRet;
        }
     }
     return new Component[] {comp};
}
 
Example 2
Source File: DynamicMenu.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected static void enableMenu (JMenu menu) {
    boolean enabled = false;
    for (int i = 0; i < menu.getItemCount(); ++i) {
        JMenuItem item = menu.getItem(i);
        if (item != null && item.isEnabled()) {
            enabled = true;
            break;
        }
    }
    menu.setEnabled(enabled);
}
 
Example 3
Source File: DynamicMenu.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected static void enableMenu (JMenu menu) {
    boolean enabled = false;
    for (int i = 0; i < menu.getItemCount(); ++i) {
        JMenuItem item = menu.getItem(i);
        if (item != null && item.isEnabled()) {
            enabled = true;
            break;
        }
    }
    menu.setEnabled(enabled);
}
 
Example 4
Source File: ShelveChangesMenu.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void enableMenu (JMenu menu) {
    boolean enabled = false;
    for (int i = 0; i < menu.getItemCount(); ++i) {
        JMenuItem item = menu.getItem(i);
        if (item != null && item.isEnabled()) {
            enabled = true;
            break;
        }
    }
    menu.setEnabled(enabled);
}
 
Example 5
Source File: DynamicMenu.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected static void enableMenu (JMenu menu) {
    boolean enabled = false;
    for (int i = 0; i < menu.getItemCount(); ++i) {
        JMenuItem item = menu.getItem(i);
        if (item != null && item.isEnabled()) {
            enabled = true;
            break;
        }
    }
    menu.setEnabled(enabled);
}
 
Example 6
Source File: NbMenuItem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
     * @param it
     * @return instance of NbMenuItem constructed from parameter it */
    public NbMenuItem(JMenuItem it) {
        setName(it.getText());//getLabel();
        this.accelerator = (it.getAccelerator() == null) ? null : it.getAccelerator().toString();
        this.mnemo = (char) it.getMnemonic();
//        System.out.println("NbMenuItem ["+name+"] - mnemo: ["+it.getMnemonic()+"]"); why are the mnemonic always in capital?
        this.enabled = it.isEnabled();
        this.checkbox = it instanceof JCheckBoxMenuItem;
        this.radiobutton = it instanceof JRadioButtonMenuItem;
        this.checked = it.isSelected();
    }
 
Example 7
Source File: NbMenuItem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
     * @param it
     * @return instance of NbMenuItem constructed from parameter it */
    public NbMenuItem(JMenuItem it) {
        setName(it.getText());//getLabel();
        this.accelerator = (it.getAccelerator() == null) ? null : it.getAccelerator().toString();
        this.mnemo = (char) it.getMnemonic();
//        System.out.println("NbMenuItem ["+name+"] - mnemo: ["+it.getMnemonic()+"]"); why are the mnemonic always in capital?
        this.enabled = it.isEnabled();
        this.checkbox = it instanceof JCheckBoxMenuItem;
        this.radiobutton = it instanceof JRadioButtonMenuItem;
        this.checked = it.isSelected();
    }
 
Example 8
Source File: MainMenu.java    From nmonvisualizer with Apache License 2.0 5 votes vote down vote up
void enableChartSubMenu(boolean enabled) {
    // View -> Chart
    JMenuItem item = getMenu(1).getItem(2);

    if (item.isEnabled() != enabled) {
        item.setEnabled(enabled);
    }
}