All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.JPopupMenu

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----com.sun.java.swing.JComponent
                           |
                           +----com.sun.java.swing.JPopupMenu

public class JPopupMenu
extends JComponent
implements Accessible, MenuElement
An implementation of a Popup Menu -- a small window which 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 the keyboard keys used by this component in the standard Look and Feel (L&F) renditions, see the JPopupMenu key assignments.

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 Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.


Constructor Index

 o JPopupMenu()
Create a JPopupMenu without an "invoker".
 o JPopupMenu(String)
Create a JPopupMenu with the specified title.

Method Index

 o add(Action)
Append a new menuitem to the end of the menu which dispatches the specified Action object.
 o add(Component)
Appends the specified component to the end of this menu.
 o add(JMenuItem)
Appends the specified menu item to the end of this menu.
 o addPopupMenuListener(PopupMenuListener)
Add a PopupMenu listener param l the PopupMenuListener to add
 o addSeparator()
 o createActionChangeListener(JMenuItem)
 o firePopupMenuCanceled()
Notifies PopupMenuListeners that this popup menu is canceled
 o firePopupMenuWillBecomeInvisible()
Notifies PopupMenuListeners that this popup menu will become invisible
 o firePopupMenuWillBecomeVisible()
Notifies PopupMenuListeners that this popup menu will become visible
 o getAccessibleContext()
Get the AccessibleContext associated with this JComponent
 o getComponent()
 o getComponentAtIndex(int)
Returns the component at the specified index.
 o getComponentIndex(Component)
Returns the index of the specified component.
 o getDefaultLightWeightPopupEnabled()
Return the default value for the lightWeightPopupEnabled property.
 o getInvoker()
Returns the component which is the 'invoker' of this popup menu.
 o getLabel()
Returns the popup menu's label
 o getMargin()
Returns the margin between the popupmenu's border and its containees.
 o getSelectionModel()
Returns the model object that handles single selections.
 o getSubElements()
 o getUI()
Returns the L&F object that renders this component.
 o getUIClassID()
Returns the name of the L&F class that renders this component.
 o insert(Action, int)
Inserts a menu item for the specified Action object at a given position.
 o insert(Component, int)
Inserts the specified component into the menu at a given position.
 o isBorderPainted()
Checks whether the border should be painted.
 o isLightWeightPopupEnabled()
Returns true if lightweight (all-Java) popups are in use, or false if heavyweight (native peer) popups are being used.
 o isVisible()
Returns true if the popupmenu is visible (currently being displayed).
 o menuSelectionChanged(boolean)
 o pack()
Layout the container so that it uses the minimum space needed to display its contents.
 o paintBorder(Graphics)
Paint the popup menu's border if BorderPainted property is true.
 o processKeyEvent(KeyEvent, MenuElement[], MenuSelectionManager)
 o processMouseEvent(MouseEvent, MenuElement[], MenuSelectionManager)
 o removePopupMenuListener(PopupMenuListener)
Remove a PopupMenu listener param l the PopupMenuListener to remove
 o setBorderPainted(boolean)
Sets whether the border should be painted.
 o setDefaultLightWeightPopupEnabled(boolean)
Set the default value for the lightWeightPopupEnabled property.
 o setInvoker(Component)
Sets the invoker of this popupmenu -- the component in which the popupmenu menu is to be displayed.
 o setLabel(String)
Sets the popup menu's label.
 o setLightWeightPopupEnabled(boolean)
When displaying the popup, JPopupMenu choose to use a light weight popup if it fits.
 o setLocation(int, int)
Set the location of the upper left corner of the popup menu using x, y coordinates.
 o setPopupSize(Dimension)
Sets the size of the Popup window using a Dimension object.
 o setPopupSize(int, int)
Sets the size of the Popup window to the specified width and height.
 o setSelected(Component)
Sets the currently selected component, This will result in a change to the selection model.
 o setSelectionModel(SingleSelectionModel)
Set the model object to handle single selections.
 o setUI(PopupMenuUI)
Sets the L&F object that renders this component.
 o setVisible(boolean)
 o show(Component, int, int)
Display the popupmenu at the position x,y in the coordinate space of the component invoker.
 o updateUI()
Notification from the UIFactory that the L&F has changed.

Constructors

 o JPopupMenu
 public JPopupMenu()
Create a JPopupMenu without an "invoker".

 o JPopupMenu
 public JPopupMenu(String label)
Create a JPopupMenu with the specified title.

Parameters:
label - The string that a UI may use to display as a title for the popup menu.

Methods

 o setDefaultLightWeightPopupEnabled
 public static void setDefaultLightWeightPopupEnabled(boolean aFlag)
Set the default value for the lightWeightPopupEnabled property.

 o getDefaultLightWeightPopupEnabled
 public static boolean getDefaultLightWeightPopupEnabled()
Return the default value for the lightWeightPopupEnabled property.

 o getUI
 public PopupMenuUI getUI()
Returns the L&F object that renders this component.

Returns:
the PopupMenuUI object that renders this component
 o setUI
 public void setUI(PopupMenuUI ui)
Sets the L&F object that renders this component.

Parameters:
ui - the new PopupMenuUI L&F object
See Also:
getUI
 o updateUI
 public void updateUI()
Notification from the UIFactory that the L&F has changed. Called to replace the UI with the latest version from the UIFactory.

Overrides:
updateUI in class JComponent
See Also:
updateUI
 o getUIClassID
 public String getUIClassID()
Returns the name of the L&F class that renders this component.

Returns:
"PopupMenuUI"
Overrides:
getUIClassID in class JComponent
See Also:
getUIClassID, getUI
 o getSelectionModel
 public SingleSelectionModel getSelectionModel()
Returns the model object that handles single selections.

Returns:
the SingleSelectionModel in use
See Also:
SingleSelectionModel
 o setSelectionModel
 public void setSelectionModel(SingleSelectionModel model)
Set the model object to handle single selections.

Parameters:
model - the SingleSelectionModel to use
See Also:
SingleSelectionModel
 o add
 public JMenuItem add(JMenuItem menuItem)
Appends the specified menu item to the end of this menu.

Parameters:
c - the JMenuItem to add
Returns:
the JMenuItem added.
 o add
 public Component add(Component c)
Appends the specified component to the end of this menu.

Parameters:
c - the Component to add
Returns:
the Component added.
Overrides:
add in class Container
 o add
 public JMenuItem add(Action a)
Append a new menuitem to the end of the menu which dispatches the specified Action object.

Parameters:
a - the Action to add to the menu
See Also:
Action
 o createActionChangeListener
 protected PropertyChangeListener createActionChangeListener(JMenuItem b)
 o setLightWeightPopupEnabled
 public void setLightWeightPopupEnabled(boolean aFlag)
When displaying the popup, JPopupMenu choose to use a light weight popup if it fits. This method allows you to disable this feature. You have to do disable it if your application mixes light weight and heavy weights components.

 o isLightWeightPopupEnabled
 public boolean isLightWeightPopupEnabled()
Returns true if lightweight (all-Java) popups are in use, or false if heavyweight (native peer) popups are being used.

Returns:
true if lightweight popups are in use
 o getLabel
 public String getLabel()
Returns the popup menu's label

See Also:
setLabel
 o setLabel
 public void setLabel(String label)
Sets the popup menu's label. Different Look and Feels may choose to display or not display this.

Parameters:
label - the label for the popup menu
See Also:
getText
 o addSeparator
 public void addSeparator()
 o insert
 public void insert(Action a,
                    int index)
Inserts a menu item for the specified Action object at a given position.

Parameters:
component - the Action object to insert
index - an int specifying the position at which to insert the Action, where 0 is the first
See Also:
Action
 o insert
 public void insert(Component component,
                    int index)
Inserts the specified component into the menu at a given position.

Parameters:
component - the Component to insert
index - an int specifying the position at which to insert the component, where 0 is the first
 o addPopupMenuListener
 public void addPopupMenuListener(PopupMenuListener l)
Add a PopupMenu listener param l the PopupMenuListener to add

 o removePopupMenuListener
 public void removePopupMenuListener(PopupMenuListener l)
Remove a PopupMenu listener param l the PopupMenuListener to remove

 o firePopupMenuWillBecomeVisible
 protected void firePopupMenuWillBecomeVisible()
Notifies PopupMenuListeners that this popup menu will become visible

 o firePopupMenuWillBecomeInvisible
 protected void firePopupMenuWillBecomeInvisible()
Notifies PopupMenuListeners that this popup menu will become invisible

 o firePopupMenuCanceled
 protected void firePopupMenuCanceled()
Notifies PopupMenuListeners that this popup menu is canceled

 o pack
 public void pack()
Layout the container so that it uses the minimum space needed to display its contents.

 o setVisible
 public void setVisible(boolean b)
Overrides:
setVisible in class JComponent
 o isVisible
 public boolean isVisible()
Returns true if the popupmenu is visible (currently being displayed).

Overrides:
isVisible in class Component
 o setLocation
 public void setLocation(int x,
                         int y)
Set the location of the upper left corner of the popup menu using x, y coordinates.

Parameters:
x - the x coordinate of the popup's new position
y - the y coordinate of the popup's new position
Overrides:
setLocation in class Component
 o getInvoker
 public Component getInvoker()
Returns the component which is the 'invoker' of this popup menu.

Returns:
the Component in which the popup menu is displayed
 o setInvoker
 public void setInvoker(Component invoker)
Sets the invoker of this popupmenu -- the component in which the popupmenu menu is to be displayed.

Parameters:
invoker - the Component in which the popup menu is displayed
 o show
 public void show(Component invoker,
                  int x,
                  int y)
Display the popupmenu at the position x,y in the coordinate space of the component invoker.

Parameters:
invoker - The component in whose space the popupmenu is to appear
x - the x coordinate in invoker's coordinate space at which the popup menu is to be displayed
y - the y coordinate in invoker's coordinate space at which the popup menu is to be displayed
 o getComponentIndex
 public int getComponentIndex(Component c)
Returns the index of the specified component.

Parameters:
the - Component to find
Returns:
the index of the component, where 0 is the first, or -1 if the component is not found
 o getComponentAtIndex
 public Component getComponentAtIndex(int i)
Returns the component at the specified index.

Parameters:
i - the index of the component, where 0 is the first
Returns:
the Component at that index
 o setPopupSize
 public void setPopupSize(Dimension d)
Sets the size of the Popup window using a Dimension object.

Parameters:
d - The dimension specifying the new size of this component.
 o setPopupSize
 public void setPopupSize(int width,
                          int height)
Sets the size of the Popup window to the specified width and height.

Parameters:
width - The new width of the Popup in pixels.
height - The new height of the Popup in pixels.
 o setSelected
 public void setSelected(Component sel)
Sets the currently selected component, This will result in a change to the selection model.

Parameters:
sel - the Component to select
 o isBorderPainted
 public boolean isBorderPainted()
Checks whether the border should be painted.

Returns:
true if the border is painted
See Also:
setBorderPainted
 o setBorderPainted
 public void setBorderPainted(boolean b)
Sets whether the border should be painted.

Parameters:
b - if true, the border is painted.
See Also:
isBorderPainted
 o paintBorder
 protected void paintBorder(Graphics g)
Paint the popup menu's border if BorderPainted property is true.

Overrides:
paintBorder in class JComponent
See Also:
paint, setBorder
 o getMargin
 public Insets getMargin()
Returns the margin between the popupmenu's border and its containees. return an Insets object containing the margin values.

 o getAccessibleContext
 public AccessibleContext getAccessibleContext()
Get the AccessibleContext associated with this JComponent

Returns:
the AccessibleContext of this JComponent
Overrides:
getAccessibleContext in class JComponent
 o processMouseEvent
 public void processMouseEvent(MouseEvent event,
                               MenuElement path[],
                               MenuSelectionManager manager)
 o processKeyEvent
 public void processKeyEvent(KeyEvent e,
                             MenuElement path[],
                             MenuSelectionManager manager)
 o menuSelectionChanged
 public void menuSelectionChanged(boolean isIncluded)
 o getSubElements
 public MenuElement[] getSubElements()
 o getComponent
 public Component getComponent()

All Packages  Class Hierarchy  This Package  Previous  Next  Index