buoy.widget
Class BPopupMenu
- MenuWidget
A BPopupMenu is a WidgetContainer corresponding to a popup menu. It is typically displayed in
response to a
WidgetMouseEvent
whose
isPopupTrigger()
method returns true. The exact conditions which represent a popup trigger are platform specific.
The easiest way to add a popup menu to a widget is to invoke
widget.addEventLink(WidgetMouseEvent.class, popup, "show");
on the widget. This will automatically take care of showing the menu whenever the user performs
the appropriate action. Alternatively, you can write your own code to listen for the event and
call
show()
on the popup menu. For example, you might want to disable certain
menu items before showing it based on the position of the mouse click.
void | add(MenuWidget widget) - Add a MenuWidget (typically a BMenuItem or BMenu) to the end of the menu.
|
void | add(MenuWidget widget, int index) - Add a MenuWidget (typically a BMenuItem or another BMenu) to the menu.
|
void | addSeparator() - Add a dividing line (a BSeparator) to the end of the menu.
|
MenuWidget | getChild(int i) - Get the i'th child of this container.
|
int | getChildCount() - Get the number of children in this container.
|
Collection | getChildren() - Get a Collection containing all child Widgets of this container.
|
JPopupMenu | getComponent() - Get the java.awt.Component corresponding to this Widget.
|
void | layoutChildren() - Layout the child Widgets.
|
void | remove(Widget widget) - Remove a child Widget from this container.
|
void | removeAll() - Remove all child Widgets from this container.
|
void | show(WidgetMouseEvent event) - Display the popup menu in response to an event.
|
void | show(Widget widget, int x, int y) - Display the popup menu over another Widget.
|
addEventLink , dispatchEvent , getBackground , getBounds , getComponent , getCursor , getFont , getMaximumSize , getMinimumSize , getName , getParent , getPreferredSize , hasFocus , isEnabled , isFocusable , isVisible , repaint , requestFocus , setBackground , setCursor , setEnabled , setFocusable , setFont , setName , setVisible |
BPopupMenu
public BPopupMenu()
Create a new BPopupMenu.
add
public void add(MenuWidget widget)
Add a MenuWidget (typically a BMenuItem or BMenu) to the end of the menu.
add
public void add(MenuWidget widget,
int index)
Add a MenuWidget (typically a BMenuItem or another BMenu) to the menu.
widget
- the MenuWidget to addindex
- the position at which to add it
addSeparator
public void addSeparator()
Add a dividing line (a BSeparator) to the end of the menu.
getChild
public MenuWidget getChild(int i)
Get the i'th child of this container.
getChildren
public Collection getChildren()
Get a Collection containing all child Widgets of this container.
- getChildren in interface WidgetContainer
getComponent
public JPopupMenu getComponent()
Get the java.awt.Component corresponding to this Widget.
- getComponent in interface Widget
layoutChildren
public void layoutChildren()
Layout the child Widgets. This may be invoked whenever something has changed (the size of this
WidgetContainer, the preferred size of one of its children, etc.) that causes the layout to no
longer be correct. If a child is itself a WidgetContainer, its layoutChildren() method will be
called in turn.
- layoutChildren in interface WidgetContainer
show
public void show(WidgetMouseEvent event)
Display the popup menu in response to an event. If
event.isPopupTrigger()
returns false, this method returns without doing anything. Otherwise it shows the popup,
determining the appropriate location based on information stored in the event.
This version of show() is provided as a convenience. It allows you to very easily add
a popup menu to a Widget by invoking
widget.addEventLink(WidgetMouseEvent.class, popup, "show");
event
- the user event which is triggering the popup menu
show
public void show(Widget widget,
int x,
int y)
Display the popup menu over another Widget.
widget
- the Widget over which to display the popup menux
- the x coordinate at which to display the popup menuy
- the y coordinate at which to display the popup menu
Written by Peter Eastman.