Java Utililty Methods Swing Menu

List of utility methods to do Swing Menu

Description

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

Method

voidaddBooleanActionTo(Container menuOrToolBar, Action action)
Creates a JCheckBoxMenuItem for a menu or JToggleButton for a tool bar
Method addButton;
try {
    addButton = Container.class.getMethod("add", Component.class);
    if (menuOrToolBar instanceof JMenu) {
        addButton.invoke(menuOrToolBar, new JCheckBoxMenuItem(action));
    } else {
        final JToggleButton jToggleButton = new JToggleButton(action);
        jToggleButton.setText(null);
...
voidaddHoverEffect4MenuAbout(final Component component, final Color overbgcolor, final Color overfgcolor, final Color outbgcolor, final Color outfgcolor)
add Hover Effect Menu About
component.addMouseListener(new MouseInputAdapter() {
    @Override
    public void mouseEntered(MouseEvent e) {
        component.setBackground(overbgcolor);
        component.setForeground(overfgcolor);
    @Override
    public void mouseExited(MouseEvent e) {
...
voidaddRCMenuMouseListener(final JTextComponent text)
add RC Menu Mouse Listener
text.addMouseListener(new MouseAdapter() {
    @Override
    public void mousePressed(MouseEvent e) {
        if (e.isMetaDown() && text.isEnabled()) {
            text.requestFocus();
            showRCMenu(text, e);
});
voidappendMenuSubElements(MenuElement element, StringBuilder builder, String indent)
append Menu Sub Elements
for (MenuElement subItem : element.getSubElements()) {
    appendMenuItem((Component) subItem, builder, indent);
voidapplyContextMenuFontRecurse(MenuElement item, Font font)
apply Context Menu Font Recurse
if (!isApplyFontRecurseEnabled) {
    return;
applyToolStripFontRecurse(item, font);
JMenubuildManualsMenu(File appDir)
build Manuals Menu
JMenu manuals = new JMenu("Manuals");
File manualsDir = new File(appDir.getPath() + File.separatorChar + "manual");
if (manualsDir.exists() && manualsDir.isDirectory()) {
    for (File manualDirContent : manualsDir.listFiles()) {
        if (manualDirContent.isDirectory()) {
            for (final File manual : manualDirContent.listFiles()) {
                if (manual.getName().contains(".pdf")) {
                    JMenuItem manualAction = new JMenuItem(manualDirContent.getName());
...
JMenuconstructViewMenu(ActionListener act, boolean showUMLOption, boolean showShortenedSourceOption, boolean showJavadocsOption, boolean showSourceOption)
Constructs a JMenu holding options to view a SingleUMLGUI, ShortenedSourceGUI, JavadocsGUI, or SourceCodeGUI for an Interface object.
JMenu viewMenu = new JMenu("View");
if (showUMLOption) {
    JMenuItem viewUML = new JMenuItem("Single UML");
    viewUML.setActionCommand("view.uml");
    viewUML.addActionListener(act);
    viewMenu.add(viewUML);
if (showShortenedSourceOption) {
...
JPopupMenucreateActionMenu(JTextComponent text, boolean includeModifying)
Creates a menu for a text component with select, copy and optionally cut and paste actions.
JPopupMenu menu = new JPopupMenu();
Action[] actions = text.getActions();
Map<String, Action> actionMap = new HashMap<>(actions.length);
for (Action action : actions) {
    actionMap.put((String) action.getValue(Action.NAME), action);
menu.add(setActionName("Select All", actionMap.get(DefaultEditorKit.selectAllAction)));
menu.add(setActionName("Copy", actionMap.get(DefaultEditorKit.copyAction)));
...
JMenucreateMenu(final String label, final String mnemonic, final String accessibleDescription)
Create a menu.
JMenu menu = new JMenu(label);
menu.setMnemonic(mnemonic.charAt(0));
menu.getAccessibleContext().setAccessibleDescription(accessibleDescription);
return menu;
JMenucreateMenu(final String name, final int mnemonic)
create Menu
final JMenu menu = new JMenu(name);
menu.setMnemonic(mnemonic);
return menu;