public class MenuDropDownButton
extends javax.swing.JToggleButton
implements javax.swing.MenuElement
Component
s of
arbitrary complexity.
The popup component(s) can be added through the constructor or after
construction through the various add methods, for example in a
popupMenuWillBecomeVisible
method of a PopupMenuListener
added to this button.Modifier and Type | Class and Description |
---|---|
protected class |
MenuDropDownButton.AccessibleMenuButton
Taken more or less verbatim from
JMenu.AccessibleJMenu and its
superclass JMenu.AccessibleJMenuItem . |
class |
MenuDropDownButton.ButtonListener |
javax.swing.JToggleButton.AccessibleJToggleButton, javax.swing.JToggleButton.ToggleButtonModel
javax.swing.AbstractButton.AccessibleAbstractButton, javax.swing.AbstractButton.ButtonChangeListener
javax.swing.JComponent.AccessibleJComponent
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Constructor and Description |
---|
MenuDropDownButton(javax.swing.AbstractButton button,
java.awt.Component... components) |
MenuDropDownButton(javax.swing.AbstractButton button,
java.lang.String tip,
java.awt.Component... components) |
MenuDropDownButton(javax.swing.Icon icon,
java.awt.Component... components) |
MenuDropDownButton(javax.swing.Icon icon,
java.lang.String tip,
java.awt.Component... components) |
MenuDropDownButton(java.lang.String text,
javax.swing.Icon icon,
java.awt.Component... components) |
MenuDropDownButton(java.lang.String text,
javax.swing.Icon icon,
java.lang.String tip,
java.awt.Component... components) |
Modifier and Type | Method and Description |
---|---|
javax.swing.JMenuItem |
add(javax.swing.Action action)
Adds a new
JMenuItem derived from an Action at the end of
the popup menu. |
void |
add(java.awt.Component... components)
Adds components at the end of the popup menu.
|
java.awt.Component |
add(java.awt.Component c)
Adds a component at the end of the popup menu.
|
java.awt.Component |
add(java.awt.Component component,
int index)
Adds a component at a position in the popup menu.
|
javax.swing.JMenuItem |
add(javax.swing.JMenuItem menuItem)
Adds a
JMenuItem at the end of the popup menu. |
javax.swing.JMenuItem |
add(java.lang.String text)
Adds a new
JMenuItem at the end of the popup menu. |
void |
addPopupMenuListener(javax.swing.event.PopupMenuListener listener) |
javax.accessibility.AccessibleContext |
getAccessibleContext() |
java.awt.Component |
getComponent() |
java.awt.Dimension |
getMaximumSize()
Overridden to add space for the drop down arrow to the width.
|
java.awt.Component |
getMenuComponent(int index) |
int |
getMenuComponentCount() |
java.awt.Component[] |
getMenuComponents() |
javax.swing.JMenuItem |
getMenuItem(int index) |
java.awt.Dimension |
getMinimumSize()
Overridden to add space for the drop down arrow to the width.
|
javax.swing.JPopupMenu |
getPopupMenu()
Gets the popup menu.
|
java.awt.Dimension |
getPreferredSize()
Overridden to add space for the drop down arrow to the width and to
limit the height to to the height of the contained button, if any.
|
javax.swing.MenuElement[] |
getSubElements() |
protected void |
hidePopup()
Hide the popup if it is showing.
|
protected boolean |
isPopupVisible() |
void |
layout() |
void |
menuSelectionChanged(boolean isIncluded) |
void |
paint(java.awt.Graphics g)
Overridden to paint the drop arrow in the space reserved for it.
|
void |
processKeyEvent(java.awt.event.KeyEvent event,
javax.swing.MenuElement[] path,
javax.swing.MenuSelectionManager manager) |
void |
processMouseEvent(java.awt.event.MouseEvent e)
Ensures that a MOUSE_PRESSED is not propagated while the popup is
cancelling (see
Tracker#propertyChange ) and otherwise ensures that
a MOUSE_PRESSED requests focus. |
void |
processMouseEvent(java.awt.event.MouseEvent event,
javax.swing.MenuElement[] path,
javax.swing.MenuSelectionManager manager) |
void |
remove(java.awt.Component component)
Removes a component from the popup menu.
|
void |
remove(int position)
Removes the component at a position from the popup menu.
|
void |
remove(javax.swing.JMenuItem item)
Removes a
JMenuItem from the popup menu. |
void |
removeAll()
Removes all component from the popup menu.
|
void |
removePopupMenuListener(javax.swing.event.PopupMenuListener listener) |
void |
setBorder(javax.swing.border.Border border) |
void |
setMargin(java.awt.Insets margin) |
void |
setRolloverEnabled(boolean enabled) |
protected void |
showPopup()
Shows the popup menu if it is not showing.
|
actionPropertyChanged, addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, configurePropertiesFromAction, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public MenuDropDownButton(java.lang.String text, javax.swing.Icon icon, java.awt.Component... components)
public MenuDropDownButton(javax.swing.Icon icon, java.awt.Component... components)
public MenuDropDownButton(javax.swing.Icon icon, java.lang.String tip, java.awt.Component... components)
public MenuDropDownButton(java.lang.String text, javax.swing.Icon icon, java.lang.String tip, java.awt.Component... components)
public MenuDropDownButton(javax.swing.AbstractButton button, java.awt.Component... components)
public MenuDropDownButton(javax.swing.AbstractButton button, java.lang.String tip, java.awt.Component... components)
public void addPopupMenuListener(javax.swing.event.PopupMenuListener listener)
public void removePopupMenuListener(javax.swing.event.PopupMenuListener listener)
public void setMargin(java.awt.Insets margin)
setMargin
in class javax.swing.AbstractButton
public void setBorder(javax.swing.border.Border border)
setBorder
in class javax.swing.JComponent
public void setRolloverEnabled(boolean enabled)
setRolloverEnabled
in class javax.swing.AbstractButton
public java.awt.Dimension getMinimumSize()
getMinimumSize
in class javax.swing.JComponent
public java.awt.Dimension getPreferredSize()
getPreferredSize
in class javax.swing.JComponent
public java.awt.Dimension getMaximumSize()
getMaximumSize
in class javax.swing.JComponent
public void layout()
layout
in class java.awt.Container
public void paint(java.awt.Graphics g)
paint
in class javax.swing.JComponent
public javax.swing.JPopupMenu getPopupMenu()
public javax.swing.JMenuItem add(javax.swing.JMenuItem menuItem)
JMenuItem
at the end of the popup menu.JMenuItem
.public java.awt.Component add(java.awt.Component c)
add
in class java.awt.Container
public java.awt.Component add(java.awt.Component component, int index)
-1
adds to the end.add
in class java.awt.Container
public void add(java.awt.Component... components)
public javax.swing.JMenuItem add(java.lang.String text)
JMenuItem
at the end of the popup menu.text
- the text of the menu item to be addedJMenuItem
.public javax.swing.JMenuItem add(javax.swing.Action action)
JMenuItem
derived from an Action
at the end of
the popup menu.action
- the action from which to derive text, icon, selected, etc.JMenuItem
.public void remove(javax.swing.JMenuItem item)
JMenuItem
from the popup menu.public void remove(int position)
remove
in class java.awt.Container
public void remove(java.awt.Component component)
remove
in class java.awt.Container
public void removeAll()
removeAll
in class java.awt.Container
public int getMenuComponentCount()
public java.awt.Component getMenuComponent(int index)
public javax.swing.JMenuItem getMenuItem(int index)
public java.awt.Component[] getMenuComponents()
protected void showPopup()
protected void hidePopup()
protected boolean isPopupVisible()
public java.awt.Component getComponent()
getComponent
in interface javax.swing.MenuElement
public void processMouseEvent(java.awt.event.MouseEvent event, javax.swing.MenuElement[] path, javax.swing.MenuSelectionManager manager)
processMouseEvent
in interface javax.swing.MenuElement
public void processKeyEvent(java.awt.event.KeyEvent event, javax.swing.MenuElement[] path, javax.swing.MenuSelectionManager manager)
processKeyEvent
in interface javax.swing.MenuElement
public void menuSelectionChanged(boolean isIncluded)
menuSelectionChanged
in interface javax.swing.MenuElement
public javax.swing.MenuElement[] getSubElements()
getSubElements
in interface javax.swing.MenuElement
public void processMouseEvent(java.awt.event.MouseEvent e)
Tracker#propertyChange
) and otherwise ensures that
a MOUSE_PRESSED requests focus. Note that using a MouseListener
rather than overriding processMouseEvent
does not seem to work
because it runs later, after Tracker#popupCancelling
has gone back
to false
.processMouseEvent
in class javax.swing.JComponent
public javax.accessibility.AccessibleContext getAccessibleContext()
getAccessibleContext
in interface javax.accessibility.Accessible
getAccessibleContext
in class javax.swing.JToggleButton