|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JMenuBar
net.sf.sdedit.ui.components.MenuBar
public class MenuBar
This is a slightly advanced JMenuBar subclass that allows to structure a menu by means of category names, so a user is not required to build JMenus. Furthermore, MenuBar provides a convenient way to define mnemonics for menu entries (by using the '&'-notation as known from Qt).
When an Action or JMenuItem is added to the MenuBar, a title string must be specified. If the string has a prefix that starts with '[' and ends with ']', the substring between these square brackets represents the accelerator key for the action or item. The appropriate key for the string is found as described here: javax.swing.Keystroke#getKeyStroke(java.lang.String).
If a title string contains an '&', the following character is used as the mnemonic for the entry or action. This also applies to categories/sub-menus.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JMenuBar |
|---|
JMenuBar.AccessibleJMenuBar |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary |
|---|
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
MenuBar()
Creates a new empty MenuBar. |
|
| Method Summary | ||
|---|---|---|
JMenuItem |
addAction(String category,
Action action)
Adds an action in the given category. |
|
JMenuItem |
addAction(String category,
Action action,
int pos)
Adds an Action to a (sub-)menu of this MenuBar. |
|
void |
addItem(String category,
JMenuItem item)
Adds an item to the given category. |
|
void |
addMenu(String category,
ImageIcon icon)
Adds a new (sub-)menu to this MenuBar. |
|
Action |
getActionByName(String name)
Returns an action that has formerly been added by addAction(String, Action) or addAction(String, Action, int). |
|
static
|
makeMenuItem(String title,
Class<T> itemType)
Creates an instance of a subclass of JMenuItem with the given title (possibly specifying an accelerator key or a mnemonic as described here: MenuBar). |
|
void |
removeAction(String category,
Action action)
Removes an action from a category. |
|
void |
updateUI()
|
|
| Methods inherited from class javax.swing.JMenuBar |
|---|
add, addNotify, getAccessibleContext, getComponent, getComponentAtIndex, getComponentIndex, getHelpMenu, getMargin, getMenu, getMenuCount, getSelectionModel, getSubElements, getUI, getUIClassID, isBorderPainted, isSelected, menuSelectionChanged, paintBorder, paramString, processKeyBinding, processKeyEvent, processMouseEvent, removeNotify, setBorderPainted, setHelpMenu, setMargin, setSelected, setSelectionModel, setUI |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public MenuBar()
| Method Detail |
|---|
public Action getActionByName(String name)
name - the name of the action
public static <T extends JMenuItem> T makeMenuItem(String title,
Class<T> itemType)
T - the type of the JMenuItem to be createdtitle - the title of the itemitemType - the type of the JMenuItem, represented as a
Class object.
public void removeAction(String category,
Action action)
category - the name of the category, containing all '&'-charactersaction - the action to be removed from the category
public JMenuItem addAction(String category,
Action action,
int pos)
Example: Let a be an action to be added to the submenu "foo" of "bar". This can be done so: addAction("foo.bar",a,0). If "foo" and "bar" should have "f" resp. "b" as mnemonics, you would call addAction("&foo.&bar",a,0)
category - the string describing the category, where names belonging to
adjacent category levels are separated by '.'. Category names
may include '&' for mnemonics.action - the action to be addedpos - the position of the action in the (sub-)menu
IllegalArgumentException - if an illegal (sub-)category is specified
public void addMenu(String category,
ImageIcon icon)
category - the category of the (sub-)menu (represented by a string with
'.''s as described above)icon - an icon for the (sub-)menu or null
public JMenuItem addAction(String category,
Action action)
category - the category of the actionaction - the action to be added
IllegalArgumentException - if the category is part of a non-existing higher level
category
public void addItem(String category,
JMenuItem item)
category - the category of the actionitem - the item to be added
IllegalArgumentException - if the category is part of a non-existing higher level
categorypublic void updateUI()
updateUI in class JMenuBarJMenuBar.updateUI()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||