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

voidsetMenuUp(boolean s, JComponent c)
set Menu Up
menuIsUp = s;
if (s)
    popupMenu = c;
else
    popupMenu = null;
voidsetViewportMenu(JComponent c)
set Viewport Menu
vpMenu = c;
JPopupMenushowContextMenu()
show Context Menu
JPopupMenu menu = new JPopupMenu();
Action cutAction = new StyledEditorKit.CutAction();
String cutActionCommand = (String) cutAction.getValue(Action.ACTION_COMMAND_KEY);
JMenuItem cutItem = new JMenuItem();
cutItem.setActionCommand(cutActionCommand);
cutItem.addActionListener(cutAction);
cutItem.setText("Cut");
menu.add(cutItem);
...
voidshowRCMenu(JTextComponent text, MouseEvent e)
show RC Menu
int selStart = text.getSelectionStart();
int selEnd = text.getSelectionEnd();
JPopupMenu rightClickMenu = new JPopupMenu();
JMenuItem copyMenuItem = new JMenuItem(text.getActionMap().get(DefaultEditorKit.copyAction));
JMenuItem cutMenuItem = new JMenuItem(text.getActionMap().get(DefaultEditorKit.cutAction));
JMenuItem pasteMenuItem = new JMenuItem(text.getActionMap().get(DefaultEditorKit.pasteAction));
JMenuItem selectAllMenuItem = new JMenuItem(text.getActionMap().get(DefaultEditorKit.selectAllAction));
copyMenuItem.setText("Copy");
...
JMenutoMenu(List actions)
Make a JMenu from an Action List
JMenu menu = new JMenu();
for (Action a : actions)
    menu.add(a);
return menu;