Java Swing Menu appendMenuSubElements(MenuElement element, StringBuilder builder, String indent)

Here you can find the source of appendMenuSubElements(MenuElement element, StringBuilder builder, String indent)

Description

append Menu Sub Elements

License

Open Source License

Declaration

private static void appendMenuSubElements(MenuElement element, StringBuilder builder, String indent) 

Method Source Code


//package com.java2s;
// it under the terms of the GNU General Public License as published by

import java.awt.Component;

import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import javax.swing.JPopupMenu;

import javax.swing.JSeparator;

import javax.swing.MenuElement;

public class Main {
    static final String NEWLINE = System.lineSeparator();

    private static void appendMenuSubElements(MenuElement element, StringBuilder builder, String indent) {
        for (MenuElement subItem : element.getSubElements()) {
            appendMenuItem((Component) subItem, builder, indent);
        }/*from ww  w.j  a v a2 s  .  c  o m*/
    }

    private static void appendMenuItem(Component menuItem, StringBuilder builder, String indent) {
        if (menuItem instanceof JMenuBar) {
            appendMenuSubElements((MenuElement) menuItem, builder, indent);
        } else if (menuItem instanceof JPopupMenu) {
            appendMenuSubElements((MenuElement) menuItem, builder, indent);
        } else if (menuItem instanceof JMenuItem) {
            builder.append(NEWLINE);
            builder.append(indent);
            builder.append(((JMenuItem) menuItem).getText());
            builder.append(((JMenuItem) menuItem).isEnabled() ? "" : "[Disabled]");
            appendMenuSubElements((JMenuItem) menuItem, builder, "|   " + indent);
        } else if (menuItem instanceof JSeparator) {
            builder.append(NEWLINE);
            builder.append(indent);
            builder.append("--------");
        }
    }
}

Related

  1. addBooleanActionTo(Container menuOrToolBar, Action action)
  2. addHoverEffect4MenuAbout(final Component component, final Color overbgcolor, final Color overfgcolor, final Color outbgcolor, final Color outfgcolor)
  3. addRCMenuMouseListener(final JTextComponent text)
  4. applyContextMenuFontRecurse(MenuElement item, Font font)
  5. buildManualsMenu(File appDir)
  6. constructViewMenu(ActionListener act, boolean showUMLOption, boolean showShortenedSourceOption, boolean showJavadocsOption, boolean showSourceOption)
  7. createActionMenu(JTextComponent text, boolean includeModifying)