|
JSR-209 (Final Approval Ballot) | ||||||||||
| 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.JPopupMenu
An implementation of a popup menu -- a small window that pops up
and displays a series of choices. A JPopupMenu is used for the
menu that appears when the user selects an item on the menu bar.
It is also used for "pull-right" menu that appears when the
selects a menu item that activates it. Finally, a JPopupMenu
can also be used anywhere else you want a menu to appear. For
example, when the user right-clicks in a specified area.
For information and examples of using popup menus, see How to Use Menus in The Java Tutorial.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the
java.beans package.
Please see java.beans.XMLEncoder.
Restrictions
When AGUI is implemented on a Profile with limited support for
top-level heavyweight containers (such as
Personal Basis Profile),
then:
JPopupMenu with a
null value for invoker will cause
java.lang.UnsupportedOperationException to be thrown.
invoker is not null,
implementations of JPopupMenu will
ignore the value reported by isLightWeightPopupEnabled() and use
only lightweight containers to display popups. In this case, note that
the specified invoker must be showing when the popup is
made visible, or java.awt.IllegalComponentStateException
is thrown.
See:
| Field Summary |
| Fields inherited from class javax.swing.JComponent |
listenerList, TOOL_TIP_TEXT_KEY, 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 | |
JPopupMenu()
Constructs a JPopupMenu without an "invoker". |
|
JPopupMenu(java.lang.String label)
Constructs a JPopupMenu with the specified title. |
|
| Method Summary | |
JMenuItem |
add(Action a)
Appends a new menu item to the end of the menu which dispatches the specified Action object. |
JMenuItem |
add(JMenuItem menuItem)
Appends the specified menu item to the end of this menu. |
JMenuItem |
add(java.lang.String s)
Creates a new menu item with the specified text and appends it to the end of this menu. |
void |
addPopupMenuListener(PopupMenuListener l)
Adds a PopupMenu listener. |
void |
addSeparator()
Appends a new separator at the end of the menu. |
protected java.beans.PropertyChangeListener |
createActionChangeListener(JMenuItem b)
Returns a properly configured PropertyChangeListener
which updates the control as changes to the Action occur. |
protected JMenuItem |
createActionComponent(Action a)
Factory method which creates the JMenuItem for
Actions added to the JPopupMenu. |
protected void |
firePopupMenuCanceled()
Notifies PopupMenuListeners that this popup menu is
cancelled. |
protected void |
firePopupMenuWillBecomeInvisible()
Notifies PopupMenuListeners that this popup menu will
become invisible. |
protected void |
firePopupMenuWillBecomeVisible()
Notifies PopupMenuListeners that this popup menu will
become visible. |
java.awt.Component |
getComponent()
Returns this JPopupMenu component. |
int |
getComponentIndex(java.awt.Component c)
Returns the index of the specified component. |
static boolean |
getDefaultLightWeightPopupEnabled()
Gets the defaultLightWeightPopupEnabled property,
which by default is true. |
java.awt.Component |
getInvoker()
Returns the component which is the 'invoker' of this popup menu. |
java.lang.String |
getLabel()
Returns the popup menu's label |
java.awt.Insets |
getMargin()
Returns the margin, in pixels, between the popup menu's border and its containees. |
PopupMenuListener[] |
getPopupMenuListeners()
Returns an array of all the PopupMenuListeners added
to this JMenuItem with addPopupMenuListener(). |
SingleSelectionModel |
getSelectionModel()
Returns the model object that handles single selections. |
MenuElement[] |
getSubElements()
Returns an array of MenuElements containing the submenu
for this menu component. |
void |
insert(Action a,
int index)
Inserts a menu item for the specified Action object at
a given position. |
void |
insert(java.awt.Component component,
int index)
Inserts the specified component into the menu at a given position. |
boolean |
isBorderPainted()
Checks whether the border should be painted. |
boolean |
isLightWeightPopupEnabled()
Gets the lightWeightPopupEnabled property. |
boolean |
isPopupTrigger(java.awt.event.MouseEvent e)
Returns true if the MouseEvent is considered a popup trigger
by the JPopupMenu's currently installed UI. |
boolean |
isVisible()
Returns true if the popup menu is visible (currently being displayed). |
void |
menuSelectionChanged(boolean isIncluded)
Messaged when the menubar selection changes to activate or deactivate this menu. |
void |
pack()
Lays out the container so that it uses the minimum space needed to display its contents. |
void |
paint(java.awt.Graphics g)
Invoked by Swing to draw components. |
protected void |
paintBorder(java.awt.Graphics g)
Paints the popup menu's border if the borderPainted
property is true. |
protected void |
paintComponent(java.awt.Graphics g)
A popup menu-specific separator. |
void |
paintComponents(java.awt.Graphics g)
|
protected java.lang.String |
paramString()
Returns a string representation of this JPopupMenu. |
protected void |
printBorder(java.awt.Graphics g)
Prints the component's border. |
protected void |
printComponent(java.awt.Graphics g)
This is invoked during a printing operation. |
void |
printComponents(java.awt.Graphics g)
|
protected void |
processFocusEvent(java.awt.event.FocusEvent evt)
|
protected void |
processKeyEvent(java.awt.event.KeyEvent evt)
Processes key stroke events such as mnemonics and accelerators. |
void |
processKeyEvent(java.awt.event.KeyEvent e,
MenuElement[] path,
MenuSelectionManager manager)
This method is required to conform to the MenuElement interface, but it not implemented. |
void |
processMouseEvent(java.awt.event.MouseEvent event,
MenuElement[] path,
MenuSelectionManager manager)
This method is required to conform to the MenuElement interface, but it not implemented. |
void |
remove(int pos)
Removes the component at the specified index from this popup menu. |
void |
removePopupMenuListener(PopupMenuListener l)
Removes a PopupMenu listener. |
void |
setBorderPainted(boolean b)
Sets whether the border should be painted. |
static void |
setDefaultLightWeightPopupEnabled(boolean aFlag)
Sets the default value of the lightWeightPopupEnabled
property. |
void |
setInvoker(java.awt.Component invoker)
Sets the invoker of this popup menu -- the component in which the popup menu menu is to be displayed. |
void |
setLabel(java.lang.String label)
Sets the popup menu's label. |
void |
setLightWeightPopupEnabled(boolean aFlag)
Sets the value of the lightWeightPopupEnabled property,
which by default is true. |
void |
setLocation(int x,
int y)
Sets the location of the upper left corner of the popup menu using x, y coordinates. |
void |
setPopupSize(Dimension d)
Sets the size of the popup window using a Dimension object. |
void |
setPopupSize(int width,
int height)
Sets the size of the popup window to the specified width and height. |
void |
setSelected(java.awt.Component sel)
Sets the currently selected component, This will result in a change to the selection model. |
void |
setSelectionModel(SingleSelectionModel model)
Sets the model object to handle single selections. |
void |
setVisible(boolean b)
Sets the visibility of the popup menu. |
void |
show(java.awt.Component invoker,
int x,
int y)
Displays the popup menu at the position x,y in the coordinate space of the component invoker. |
| Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, areFocusTraversalKeysSet, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, list, list, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
| Methods inherited from class java.awt.Component |
addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getCursor, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getSize, getToolkit, getTreeLock, hasFocus, imageUpdate, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, list, list, list, paintAll, prepareImage, prepareImage, processComponentEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, setBounds, setBounds, setCursor, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setName, setSize, setSize, toString, transferFocus, transferFocusUpCycle |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public JPopupMenu()
JPopupMenu without an "invoker".
public JPopupMenu(java.lang.String label)
JPopupMenu with the specified title.
label - the string that a UI may use to display as a title
for the popup menu.| Method Detail |
public static void setDefaultLightWeightPopupEnabled(boolean aFlag)
lightWeightPopupEnabled
property.
aFlag - true if popups can be lightweight,
otherwise falsegetDefaultLightWeightPopupEnabled(),
setLightWeightPopupEnabled(boolean)public static boolean getDefaultLightWeightPopupEnabled()
defaultLightWeightPopupEnabled property,
which by default is true.
defaultLightWeightPopupEnabled
propertysetDefaultLightWeightPopupEnabled(boolean)public final void paint(java.awt.Graphics g)
JComponentpaint directly,
but should instead use the repaint method to
schedule the component for redrawing.
This method actually delegates the work of painting to three
protected methods: paintComponent,
paintBorder,
and paintChildren. They're called in the order
listed to ensure that children appear on top of component itself.
Generally speaking, the component and its children should not
paint in the insets area allocated to the border. Subclasses can
just override this method, as always.
paint in class JComponentg - the Graphics context in which to paintJComponent.paintBorder(java.awt.Graphics),
JComponent.paintChildren(java.awt.Graphics),
JComponent.getComponentGraphics(java.awt.Graphics),
JComponent.repaint(long, int, int, int, int)protected void processFocusEvent(java.awt.event.FocusEvent evt)
protected void processKeyEvent(java.awt.event.KeyEvent evt)
processKeyEvent in class JComponentevt - the key event to be processedpublic SingleSelectionModel getSelectionModel()
selectionModel propertySingleSelectionModelpublic void setSelectionModel(SingleSelectionModel model)
model - the new SingleSelectionModelSingleSelectionModelpublic JMenuItem add(JMenuItem menuItem)
menuItem - the JMenuItem to add
JMenuItem addedpublic JMenuItem add(java.lang.String s)
s - the string for the menu item to be addedpublic JMenuItem add(Action a)
Action object.
As of JDK 1.3, this is no longer the preferred method for adding
Actions to
a container. Instead it is recommended to configure a control with
an action using setAction, and then add that control
directly to the Container.
a - the Action to add to the menu
Actionprotected JMenuItem createActionComponent(Action a)
JMenuItem for
Actions added to the JPopupMenu.
As of JDK 1.3, this is no
longer the preferred method, instead it is recommended to configure
a control with an action using setAction,
and then adding that
control directly to the Container.
a - the Action for the menu item to be added
Actionprotected java.beans.PropertyChangeListener createActionChangeListener(JMenuItem b)
PropertyChangeListener
which updates the control as changes to the Action occur.
As of JDK 1.3, this is no longer the preferred method for adding
Actions to
a container. Instead it is recommended to configure a control with
an action using setAction, and then add that control
directly to the Container.
public void remove(int pos)
pos - the position of the item to be removed
java.lang.IllegalArgumentException - if the value of
pos < 0, or if the value of
pos is greater than the
number of itemspublic void setLightWeightPopupEnabled(boolean aFlag)
lightWeightPopupEnabled property,
which by default is true.
By default, when a look and feel displays a popup,
it can choose to
use a lightweight (all-Java) popup.
Lightweight popup windows are more efficient than heavyweight
(native peer) windows,
but lightweight and heavyweight components do not mix well in a GUI.
If your application mixes lightweight and heavyweight components,
you should disable lightweight popups.
Some look and feels might always use heavyweight popups,
no matter what the value of this property.
aFlag - false to disable lightweight popupsisLightWeightPopupEnabled()public boolean isLightWeightPopupEnabled()
lightWeightPopupEnabled property.
lightWeightPopupEnabled propertysetLightWeightPopupEnabled(boolean)public java.lang.String getLabel()
setLabel(java.lang.String)public void setLabel(java.lang.String label)
label - a string specifying the label for the popup menusetLabel(java.lang.String)public void addSeparator()
public void insert(Action a,
int index)
Action object at
a given position.
a - the Action object to insertindex - specifies the position at which to insert the
Action, where 0 is the first
java.lang.IllegalArgumentException - if index < 0Action
public void insert(java.awt.Component component,
int index)
component - the Component to insertindex - specifies the position at which
to insert the component, where 0 is the first
java.lang.IllegalArgumentException - if index < 0public void addPopupMenuListener(PopupMenuListener l)
PopupMenu listener.
l - the PopupMenuListener to addpublic void removePopupMenuListener(PopupMenuListener l)
PopupMenu listener.
l - the PopupMenuListener to removepublic PopupMenuListener[] getPopupMenuListeners()
PopupMenuListeners added
to this JMenuItem with addPopupMenuListener().
PopupMenuListeners added or an empty
array if no listeners have been addedprotected void firePopupMenuWillBecomeVisible()
PopupMenuListeners that this popup menu will
become visible.
protected void firePopupMenuWillBecomeInvisible()
PopupMenuListeners that this popup menu will
become invisible.
protected void firePopupMenuCanceled()
PopupMenuListeners that this popup menu is
cancelled.
public void pack()
public void setVisible(boolean b)
setVisible in class JComponentb - true to make the popup visible, or false to
hide itpublic boolean isVisible()
public void setLocation(int x,
int y)
x - the x coordinate of the popup's new positiony - the y coordinate of the popup's new positionpublic java.awt.Component getInvoker()
Component in which the popup menu is displayedpublic void setInvoker(java.awt.Component invoker)
invoker - the Component in which the popup
menu is displayed
public void show(java.awt.Component invoker,
int x,
int y)
invoker - the component in whose space the popup menu is to appearx - the x coordinate in invoker's coordinate space at which
the popup menu is to be displayedy - the y coordinate in invoker's coordinate space at which
the popup menu is to be displayedpublic int getComponentIndex(java.awt.Component c)
c - the Component to find
public void setPopupSize(Dimension d)
Dimension object.
This is equivalent to setPreferredSize(d).
d - the Dimension specifying the new size
of this component.
public void setPopupSize(int width,
int height)
setPreferredSize(new Dimension(width, height)).
width - the new width of the popup in pixelsheight - the new height of the popup in pixelspublic void setSelected(java.awt.Component sel)
sel - the Component to selectpublic boolean isBorderPainted()
setBorderPainted(boolean)public void setBorderPainted(boolean b)
b - if true, the border is painted.isBorderPainted()protected final void paintBorder(java.awt.Graphics g)
borderPainted
property is true.
paintBorder in class JComponentg - the Graphics objectJComponent.paint(java.awt.Graphics),
JComponent.setBorder(javax.swing.border.Border)public java.awt.Insets getMargin()
Insets object containing the margin values.protected java.lang.String paramString()
JPopupMenu.
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.
paramString in class JComponentJPopupMenu.
public void processMouseEvent(java.awt.event.MouseEvent event,
MenuElement[] path,
MenuSelectionManager manager)
MenuElement interface, but it not implemented.
processMouseEvent in interface MenuElementMenuElement.processMouseEvent(MouseEvent, MenuElement[], MenuSelectionManager)
public void processKeyEvent(java.awt.event.KeyEvent e,
MenuElement[] path,
MenuSelectionManager manager)
MenuElement interface, but it not implemented.
processKeyEvent in interface MenuElementMenuElement.processKeyEvent(KeyEvent, MenuElement[], MenuSelectionManager)public void menuSelectionChanged(boolean isIncluded)
javax.swing.MenuElement interface.
Overrides MenuElement.menuSelectionChanged.
menuSelectionChanged in interface MenuElementisIncluded - true if this menu is active, false if
it is notMenuElement.menuSelectionChanged(boolean)public MenuElement[] getSubElements()
MenuElements containing the submenu
for this menu component. It will only return items conforming to
the JMenuElement interface.
If popup menu is null returns
an empty array. This method is required to conform to the
MenuElement interface.
getSubElements in interface MenuElementMenuElement objectsMenuElement.getSubElements()public java.awt.Component getComponent()
JPopupMenu component.
getComponent in interface MenuElementJPopupMenu objectMenuElement.getComponent()public boolean isPopupTrigger(java.awt.event.MouseEvent e)
MouseEvent is considered a popup trigger
by the JPopupMenu's currently installed UI.
protected final void paintComponent(java.awt.Graphics g)
paintComponent in class JComponentg - the Graphics object to protectJComponent.paint(java.awt.Graphics),
ComponentUIpublic final void paintComponents(java.awt.Graphics g)
protected final void printComponent(java.awt.Graphics g)
JComponentpaintComponent on the component.
printComponent in class JComponentg - the Graphics context in which to paintJComponent.print(java.awt.Graphics)protected final void printBorder(java.awt.Graphics g)
JComponentpaintBorder on the component.
printBorder in class JComponentg - the Graphics context in which to paintJComponent.print(java.awt.Graphics)public final void printComponents(java.awt.Graphics g)
|
JSR-209 (Final Approval Ballot) | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||