Java Utililty Methods JMenu

List of utility methods to do JMenu

Description

The list of methods to do JMenu are organized into topic(s).

Method

JMenuItemmenuItem(JMenu parent, String label, Object... attrs)
Construct a new JMenuItem then add it to an existing JMenu.
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;
...
voidremoveAllSeparators(JMenu menu)
Convenience method that calls the method removeAllSeparators(JPopupMenu) with the JPopupMenu of the given menu as parameter.
removeAllSeparators(menu.getPopupMenu());
voidremoveTopAndBottomSeparators(JMenu menu)
Convenience method that calls the method removeTopAndBottomSeparators(JPopupMenu) with the JPopupMenu of the given menu as parameter.
removeTopAndBottomSeparators(menu.getPopupMenu());
voidsetChildrenEnabled(JMenu menu, boolean enabled)
Set the enabled state of a JMenu and all its children.
Component child[] = menu.getMenuComponents();
int num_children = child.length;
Component me = menu.getComponent();
if (me instanceof JComponent) {
    ((JComponent) me).setEnabled(enabled);
for (int i = 0; i < num_children; i++) {
    if (child[i] instanceof JComponent) {
...
voidtearDownMenu(JMenu menu)
Totally rip a menu apart, recursively.
Vector<JMenuItem> componentsToRemove = new Vector<JMenuItem>();
for (int i = 0; i < menu.getItemCount(); i++)
    componentsToRemove.add(menu.getItem(i));
for (JMenuItem c : componentsToRemove)
    if (c == null)
        ;
    else if (c instanceof JMenu)
        tearDownMenu((JMenu) c);
...