Methods Summary |
---|
protected void | actionPropertyChanged(javax.swing.Action action, java.lang.String propertyName){@inheritDoc}
if (propertyName == Action.ACCELERATOR_KEY) {
configureAcceleratorFromAction(action);
}
else {
super.actionPropertyChanged(action, propertyName);
}
|
public void | addMenuDragMouseListener(javax.swing.event.MenuDragMouseListener l)Adds a MenuDragMouseListener to the menu item.
listenerList.add(MenuDragMouseListener.class, l);
|
public void | addMenuKeyListener(javax.swing.event.MenuKeyListener l)Adds a MenuKeyListener to the menu item.
listenerList.add(MenuKeyListener.class, l);
|
boolean | alwaysOnTop()Returns true since Menu s, by definition,
should always be on top of all other windows. If the menu is
in an internal frame false is returned due to the rollover effect
for windows laf where the menu is not always on top.
// Fix for bug #4482165
if (SwingUtilities.getAncestorOfClass(JInternalFrame.class, this) !=
null) {
return false;
}
return true;
|
void | configureAcceleratorFromAction(javax.swing.Action a)
KeyStroke ks = (a==null) ? null :
(KeyStroke)a.getValue(Action.ACCELERATOR_KEY);
setAccelerator(ks);
|
protected void | configurePropertiesFromAction(javax.swing.Action a){@inheritDoc}
super.configurePropertiesFromAction(a);
configureAcceleratorFromAction(a);
|
protected void | fireMenuDragMouseDragged(javax.swing.event.MenuDragMouseEvent event)Notifies all listeners that have registered interest for
notification on this event type.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==MenuDragMouseListener.class) {
// Lazily create the event:
((MenuDragMouseListener)listeners[i+1]).menuDragMouseDragged(event);
}
}
|
protected void | fireMenuDragMouseEntered(javax.swing.event.MenuDragMouseEvent event)Notifies all listeners that have registered interest for
notification on this event type.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==MenuDragMouseListener.class) {
// Lazily create the event:
((MenuDragMouseListener)listeners[i+1]).menuDragMouseEntered(event);
}
}
|
protected void | fireMenuDragMouseExited(javax.swing.event.MenuDragMouseEvent event)Notifies all listeners that have registered interest for
notification on this event type.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==MenuDragMouseListener.class) {
// Lazily create the event:
((MenuDragMouseListener)listeners[i+1]).menuDragMouseExited(event);
}
}
|
protected void | fireMenuDragMouseReleased(javax.swing.event.MenuDragMouseEvent event)Notifies all listeners that have registered interest for
notification on this event type.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==MenuDragMouseListener.class) {
// Lazily create the event:
((MenuDragMouseListener)listeners[i+1]).menuDragMouseReleased(event);
}
}
|
protected void | fireMenuKeyPressed(javax.swing.event.MenuKeyEvent event)Notifies all listeners that have registered interest for
notification on this event type.
if (DEBUG) {
System.out.println("in JMenuItem.fireMenuKeyPressed for " + getText()+
" " + KeyStroke.getKeyStrokeForEvent(event));
}
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==MenuKeyListener.class) {
// Lazily create the event:
((MenuKeyListener)listeners[i+1]).menuKeyPressed(event);
}
}
|
protected void | fireMenuKeyReleased(javax.swing.event.MenuKeyEvent event)Notifies all listeners that have registered interest for
notification on this event type.
if (DEBUG) {
System.out.println("in JMenuItem.fireMenuKeyReleased for " + getText()+
" " + KeyStroke.getKeyStrokeForEvent(event));
}
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==MenuKeyListener.class) {
// Lazily create the event:
((MenuKeyListener)listeners[i+1]).menuKeyReleased(event);
}
}
|
protected void | fireMenuKeyTyped(javax.swing.event.MenuKeyEvent event)Notifies all listeners that have registered interest for
notification on this event type.
if (DEBUG) {
System.out.println("in JMenuItem.fireMenuKeyTyped for " + getText()+
" " + KeyStroke.getKeyStrokeForEvent(event));
}
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==MenuKeyListener.class) {
// Lazily create the event:
((MenuKeyListener)listeners[i+1]).menuKeyTyped(event);
}
}
|
public javax.swing.KeyStroke | getAccelerator()Returns the KeyStroke which serves as an accelerator
for the menu item.
return this.accelerator;
|
public javax.accessibility.AccessibleContext | getAccessibleContext()Returns the AccessibleContext associated with this
JMenuItem . For JMenuItem s,
the AccessibleContext takes the form of an
AccessibleJMenuItem .
A new AccessibleJMenuItme instance is created if necessary.
if (accessibleContext == null) {
accessibleContext = new AccessibleJMenuItem();
}
return accessibleContext;
|
public java.awt.Component | getComponent()Returns the java.awt.Component used to paint
this object. The returned component will be used to convert
events and detect if an event is inside a menu component.
return this;
|
public javax.swing.event.MenuDragMouseListener[] | getMenuDragMouseListeners()Returns an array of all the MenuDragMouseListener s added
to this JMenuItem with addMenuDragMouseListener().
return (MenuDragMouseListener[])listenerList.getListeners(
MenuDragMouseListener.class);
|
public javax.swing.event.MenuKeyListener[] | getMenuKeyListeners()Returns an array of all the MenuKeyListener s added
to this JMenuItem with addMenuKeyListener().
return (MenuKeyListener[])listenerList.getListeners(
MenuKeyListener.class);
|
public javax.swing.MenuElement[] | getSubElements()This method returns an array containing the sub-menu
components for this menu component.
return new MenuElement[0];
|
public java.lang.String | getUIClassID()Returns the suffix used to construct the name of the L&F class used to
render this component.
return uiClassID;
|
protected void | init(java.lang.String text, javax.swing.Icon icon)Initializes the menu item with the specified text and icon.
if(text != null) {
setText(text);
}
if(icon != null) {
setIcon(icon);
}
// Listen for Focus events
addFocusListener(new MenuItemFocusListener());
setUIProperty("borderPainted", Boolean.FALSE);
setFocusPainted(false);
setHorizontalTextPosition(JButton.TRAILING);
setHorizontalAlignment(JButton.LEADING);
updateUI();
|
void | initFocusability()Inititalizes the focusability of the the JMenuItem .
JMenuItem 's are focusable, but subclasses may
want to be, this provides them the opportunity to override this
and invoke something else, or nothing at all. Refer to
{@link javax.swing.JMenu#initFocusability} for the motivation of
this.
setFocusable(false);
|
public boolean | isArmed()Returns whether the menu item is "armed".
ButtonModel model = (ButtonModel) getModel();
return model.isArmed();
|
void | largeIconChanged(javax.swing.Action a)
|
public void | menuSelectionChanged(boolean isIncluded)Called by the MenuSelectionManager when the
MenuElement is selected or unselected.
setArmed(isIncluded);
|
protected java.lang.String | paramString()Returns a string representation of this JMenuItem .
This method is intended to be used only for debugging purposes,
and the content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be null .
return super.paramString();
|
public void | processKeyEvent(java.awt.event.KeyEvent e, javax.swing.MenuElement[] path, javax.swing.MenuSelectionManager manager)Processes a key event forwarded from the
MenuSelectionManager and changes the menu selection,
if necessary, by using MenuSelectionManager 's API.
Note: you do not have to forward the event to sub-components.
This is done automatically by the MenuSelectionManager .
if (DEBUG) {
System.out.println("in JMenuItem.processKeyEvent/3 for " + getText() +
" " + KeyStroke.getKeyStrokeForEvent(e));
}
MenuKeyEvent mke = new MenuKeyEvent(e.getComponent(), e.getID(),
e.getWhen(), e.getModifiers(),
e.getKeyCode(), e.getKeyChar(),
path, manager);
processMenuKeyEvent(mke);
if (mke.isConsumed()) {
e.consume();
}
|
public void | processMenuDragMouseEvent(javax.swing.event.MenuDragMouseEvent e)Handles mouse drag in a menu.
switch (e.getID()) {
case MouseEvent.MOUSE_ENTERED:
isMouseDragged = false; fireMenuDragMouseEntered(e); break;
case MouseEvent.MOUSE_EXITED:
isMouseDragged = false; fireMenuDragMouseExited(e); break;
case MouseEvent.MOUSE_DRAGGED:
isMouseDragged = true; fireMenuDragMouseDragged(e); break;
case MouseEvent.MOUSE_RELEASED:
if(isMouseDragged) fireMenuDragMouseReleased(e); break;
default:
break;
}
|
public void | processMenuKeyEvent(javax.swing.event.MenuKeyEvent e)Handles a keystroke in a menu.
if (DEBUG) {
System.out.println("in JMenuItem.processMenuKeyEvent for " + getText()+
" " + KeyStroke.getKeyStrokeForEvent(e));
}
switch (e.getID()) {
case KeyEvent.KEY_PRESSED:
fireMenuKeyPressed(e); break;
case KeyEvent.KEY_RELEASED:
fireMenuKeyReleased(e); break;
case KeyEvent.KEY_TYPED:
fireMenuKeyTyped(e); break;
default:
break;
}
|
public void | processMouseEvent(java.awt.event.MouseEvent e, javax.swing.MenuElement[] path, javax.swing.MenuSelectionManager manager)Processes a mouse event forwarded from the
MenuSelectionManager and changes the menu
selection, if necessary, by using the
MenuSelectionManager 's API.
Note: you do not have to forward the event to sub-components.
This is done automatically by the MenuSelectionManager .
processMenuDragMouseEvent(
new MenuDragMouseEvent(e.getComponent(), e.getID(),
e.getWhen(),
e.getModifiers(), e.getX(), e.getY(),
e.getXOnScreen(), e.getYOnScreen(),
e.getClickCount(), e.isPopupTrigger(),
path, manager));
|
private void | readObject(java.io.ObjectInputStream s)See JComponent.readObject() for information about serialization
in Swing.
s.defaultReadObject();
if (getUIClassID().equals(uiClassID)) {
updateUI();
}
|
public void | removeMenuDragMouseListener(javax.swing.event.MenuDragMouseListener l)Removes a MenuDragMouseListener from the menu item.
listenerList.remove(MenuDragMouseListener.class, l);
|
public void | removeMenuKeyListener(javax.swing.event.MenuKeyListener l)Removes a MenuKeyListener from the menu item.
listenerList.remove(MenuKeyListener.class, l);
|
public void | setAccelerator(javax.swing.KeyStroke keyStroke)Sets the key combination which invokes the menu item's
action listeners without navigating the menu hierarchy. It is the
UI's responsibility to install the correct action. Note that
when the keyboard accelerator is typed, it will work whether or
not the menu is currently displayed.
KeyStroke oldAccelerator = accelerator;
this.accelerator = keyStroke;
repaint();
revalidate();
firePropertyChange("accelerator", oldAccelerator, accelerator);
|
public void | setArmed(boolean b)Identifies the menu item as "armed". If the mouse button is
released while it is over this item, the menu's action event
will fire. If the mouse button is released elsewhere, the
event will not fire and the menu item will be disarmed.
ButtonModel model = (ButtonModel) getModel();
boolean oldValue = model.isArmed();
if(model.isArmed() != b) {
model.setArmed(b);
}
|
public void | setEnabled(boolean b)Enables or disables the menu item.
// Make sure we aren't armed!
if (!b && !UIManager.getBoolean("MenuItem.disabledAreNavigable")) {
setArmed(false);
}
super.setEnabled(b);
|
void | setIconFromAction(javax.swing.Action a)
Icon icon = null;
if (a != null) {
icon = (Icon)a.getValue(Action.SMALL_ICON);
}
setIcon(icon);
|
public void | setModel(javax.swing.ButtonModel newModel){@inheritDoc}
super.setModel(newModel);
if(newModel instanceof DefaultButtonModel) {
((DefaultButtonModel)newModel).setMenuItem(true);
}
|
public void | setUI(javax.swing.plaf.MenuItemUI ui)Sets the look and feel object that renders this component.
super.setUI(ui);
|
void | smallIconChanged(javax.swing.Action a)
setIconFromAction(a);
|
public void | updateUI()Resets the UI property with a value from the current look and feel.
setUI((MenuItemUI)UIManager.getUI(this));
|
private void | writeObject(java.io.ObjectOutputStream s)
s.defaultWriteObject();
if (getUIClassID().equals(uiClassID)) {
byte count = JComponent.getWriteObjCounter(this);
JComponent.setWriteObjCounter(this, --count);
if (count == 0 && ui != null) {
ui.installUI(this);
}
}
|