Class JDropDownButton
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
javax.swing.JButton
net.thevpc.common.swing.button.JDropDownButton
- All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, SwingConstants
- Direct Known Subclasses:
ColorChooserButton
- Author:
- Taha BEN SALAH (taha.bensalah@gmail.com) %creationtime 13 juil. 2006 22:14:21
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classA listener class that watches for a popup window closing.Nested classes/interfaces inherited from class JButton
JButton.AccessibleJButtonNested classes/interfaces inherited from class AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListenerNested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JDropDownButton.WinListenerThe window-closing listener for the popup.protected List<ActionListener> Fields inherited from class AbstractButton
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_PROPERTYFields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST -
Constructor Summary
ConstructorsConstructorDescriptionJDropDownButton(String text) JDropDownButton(String text, Icon icon) JDropDownButton(Icon icon) -
Method Summary
Modifier and TypeMethodDescriptionAppends a component to the end of this menu.Adds the specified component to this container at the given position.Creates a new menu item with the specified text and appends it to the end of this menu.Creates a new menu item attached to the specifiedActionobject and appends it to the end of this menu.Appends a menu item to the end of this menu.voidAdds a listener for menu events.voidaddQuickActionListener(ActionListener listener) voidAppends a new separator to the end of the menu.protected PropertyChangeListenerReturns a properly configuredPropertyChangeListenerwhich updates the control as changes to theActionoccur.protected JMenuItemFactory method which creates theJMenuItemforActions added to theJMenu.protected JDropDownButton.WinListenerCreates a window-closing listener for the popup.voiddoClick(int pressTime) Programmatically performs a "click".protected voidNotifies all listeners that have registered interest for notification on this event type.protected voidNotifies all listeners that have registered interest for notification on this event type.protected voidNotifies all listeners that have registered interest for notification on this event type.protected voidReturns thejava.awt.Componentused to paint thisMenuElement.intgetDelay()Returns the suggested delay, in milliseconds, before submenus are popped up or down.getItem(int pos) Returns theJMenuItemat the specified position.intReturns the number of items on the menu, including separators.getMenuComponent(int n) Returns the component at positionn.intReturns the number of components on the menu.Returns an array ofComponents of the menu's subcomponents.Returns an array of all theMenuListeners added to this JMenu with addMenuListener().Returns the popupmenu associated with this menu.protected PointComputes the origin for theJMenu's popup menu.intintReturns an array ofMenuElements containing the submenu for this menu component.voidCauses the combo box to close its popup window.voidInserts a new menu item with the specified text at a given position.Inserts a new menu item attached to the specifiedActionobject at a given position.Inserts the specifiedJMenuitemat a given position.voidinsertSeparator(int index) Inserts a separator at the specified position.protected voidbooleanReturns true if the specified component exists in the submenu hierarchy.booleanbooleanReturns true if the menu's popup window is visible.voidmenuSelectionChanged(boolean isIncluded) Messaged when the menubar selection changes to activate or deactivate this menu.protected voidvoidvoidpaintTriangle(Graphics g, int x, int y, int size, int direction, boolean isEnabled) voidremove(int pos) Removes the menu item at the specified index from this menu.voidRemoves the componentcfrom this menu.voidRemoves the specified menu item from this menu.voidRemoves all menu items from this menu.voidRemoves a listener for menu events.voidremoveQuickActionListener(ActionListener listener) voidsetDelay(int d) Sets the suggested delay before the menu'sPopupMenuis popped up or down.voidsetMenuLocation(int x, int y) Sets the location of the popup component.setPaintHandle(boolean paintHandle) voidsetPopupMenuVisible(boolean b) Sets the visibility of the menu's popup.voidsetPopupOrientation(int orientation) voidsetQuickActionDelay(int quickActionDelay) voidupdateUI()Methods inherited from class JButton
getAccessibleContext, getUIClassID, isDefaultButton, isDefaultCapable, paramString, removeNotify, setDefaultCapableMethods inherited from class AbstractButton
actionPropertyChanged, addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, configurePropertiesFromAction, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, 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, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPositionMethods inherited from class JComponent
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, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, 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, paint, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class Container
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, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusDownCycle, validate, validateTreeMethods inherited from class Component
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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
quickListeners
-
popupListener
The window-closing listener for the popup.- See Also:
-
-
Constructor Details
-
JDropDownButton
public JDropDownButton() -
JDropDownButton
-
JDropDownButton
-
JDropDownButton
-
JDropDownButton
-
-
Method Details
-
getQuickActionDelay
public int getQuickActionDelay() -
setQuickActionDelay
public void setQuickActionDelay(int quickActionDelay) -
isPaintHandle
public boolean isPaintHandle() -
setPaintHandle
-
installAncestorListener
protected void installAncestorListener() -
hidePopup
public void hidePopup()Causes the combo box to close its popup window. -
getTreeMenuItemByActionCommand
-
addQuickActionListener
-
removeQuickActionListener
-
fireQuickActionPerformed
-
getPopupOrientation
public int getPopupOrientation() -
setPopupOrientation
public void setPopupOrientation(int orientation) - Parameters:
orientation- : SwingConstants.LEFT or SwingConstants.RIGHT
-
paintHandle
-
paintComponent
- Overrides:
paintComponentin classJComponent
-
paintTriangle
-
updateUI
-
isPopupMenuVisible
public boolean isPopupMenuVisible()Returns true if the menu's popup window is visible.- Returns:
- true if the menu is visible, else false
-
setPopupMenuVisible
public void setPopupMenuVisible(boolean b) Sets the visibility of the menu's popup. If the menu is not enabled, this method will have no effect.- Parameters:
b- a boolean value -- true to make the menu visible, false to hide it @@beaninfo description: The popup menu's visibility expert: true hidden: true
-
getPopupMenuOrigin
Computes the origin for theJMenu's popup menu. This method uses Look and Feel properties namedMenu.menuPopupOffsetX,Menu.menuPopupOffsetY,Menu.submenuPopupOffsetX, andMenu.submenuPopupOffsetYto adjust the exact location of popup.- Returns:
- a
Pointin the coordinate space of the menu which should be used as the origin of theJMenu's popup menu - Since:
- 1.3
-
getDelay
public int getDelay()Returns the suggested delay, in milliseconds, before submenus are popped up or down. Each look and feel (L&F) may determine its own policy for observing thedelayproperty. In most cases, the delay is not observed for top level menus or while dragging. The default fordelayis 0. This method is a property of the look and feel code and is used to manage the idiosyncracies of the various UI implementations.- Returns:
- the
delayproperty
-
setDelay
public void setDelay(int d) Sets the suggested delay before the menu'sPopupMenuis popped up or down. Each look and feel (L#F) may determine it's own policy for observing the delay property. In most cases, the delay is not observed for top level menus or while dragging. This method is a property of the look and feel code and is used to manage the idiosyncracies of the various UI implementations.- Parameters:
d- the number of milliseconds to delay- Throws:
IllegalArgumentException- ifdis less than 0 popup menu visible expert: true
-
setMenuLocation
public void setMenuLocation(int x, int y) Sets the location of the popup component.- Parameters:
x- the x coordinate of the popup's new positiony- the y coordinate of the popup's new position
-
add
-
add
-
add
Adds the specified component to this container at the given position. Ifindexequals -1, the component will be appended to the end. -
remove
public void remove(int pos) Removes the menu item at the specified index from this menu.- Overrides:
removein classContainer- Parameters:
pos- the position of the item to be removed- Throws:
IllegalArgumentException- if the value ofpos< 0, or ifposis greater than the number of menu items
-
remove
-
removeAll
-
add
-
add
Creates a new menu item attached to the specifiedActionobject and appends it to the end of this menu. As of 1.3, this is no longer the preferred method for addingActionsto a container. Instead it is recommended to configure a control with an action usingsetAction, and then add that control directly to theContainer.- Parameters:
a- theActionfor the menu item to be added- See Also:
-
addSeparator
public void addSeparator()Appends a new separator to the end of the menu. -
insert
Inserts a new menu item with the specified text at a given position.- Parameters:
s- the text for the menu item to addpos- an integer specifying the position at which to add the new menu item- Throws:
IllegalArgumentException- when the value ofpos< 0
-
insert
Inserts the specifiedJMenuitemat a given position.- Parameters:
mi- theJMenuitemto addpos- an integer specifying the position at which to add the newJMenuitem- Returns:
- the new menu item
- Throws:
IllegalArgumentException- if the value ofpos< 0
-
insert
Inserts a new menu item attached to the specifiedActionobject at a given position.- Parameters:
a- theActionobject for the menu item to addpos- an integer specifying the position at which to add the new menu item- Throws:
IllegalArgumentException- if the value ofpos< 0
-
insertSeparator
public void insertSeparator(int index) Inserts a separator at the specified position.- Parameters:
index- an integer specifying the position at which to insert the menu separator- Throws:
IllegalArgumentException- if the value ofindex< 0
-
getItem
Returns theJMenuItemat the specified position. If the component atposis not a menu item,nullis returned. This method is included for AWT compatibility.- Parameters:
pos- an integer specifying the position- Returns:
- the menu item at the specified position; or
nullif the item as the specified position is not a menu item - Throws:
IllegalArgumentException- if the value ofpos< 0
-
getItemCount
public int getItemCount()Returns the number of items on the menu, including separators. This method is included for AWT compatibility.- Returns:
- an integer equal to the number of items on the menu
- See Also:
-
remove
Removes the specified menu item from this menu. If there is no popup menu, this method will have no effect.- Parameters:
item- theJMenuItemto be removed from the menu
-
getMenuComponentCount
public int getMenuComponentCount()Returns the number of components on the menu.- Returns:
- an integer containing the number of components on the menu
-
getMenuComponent
Returns the component at positionn.- Parameters:
n- the position of the component to be returned- Returns:
- the component requested, or
nullif there is no popup menu
-
getMenuComponents
Returns an array ofComponents of the menu's subcomponents. Note that this returns allComponents in the popup menu, including separators.- Returns:
- an array of
Components or an empty array if there is no popup menu
-
isMenuComponent
Returns true if the specified component exists in the submenu hierarchy.- Parameters:
c- theComponentto be tested- Returns:
- true if the
Componentexists, false otherwise
-
getPopupMenu
Returns the popupmenu associated with this menu. If there is no popupmenu, it will create one. -
getPopupMenuOrNull
-
addMenuListener
Adds a listener for menu events.- Parameters:
l- the listener to be added
-
removeMenuListener
Removes a listener for menu events.- Parameters:
l- the listener to be removed
-
getMenuListeners
Returns an array of all theMenuListeners added to this JMenu with addMenuListener().- Returns:
- all of the
MenuListeners added or an empty array if no listeners have been added - Since:
- 1.4
-
fireMenuSelected
protected void fireMenuSelected()Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.- Throws:
Error- if there is anulllistener- See Also:
-
fireMenuDeselected
protected void fireMenuDeselected()Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.- Throws:
Error- if there is anulllistener- See Also:
-
fireMenuCanceled
protected void fireMenuCanceled()Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.- Throws:
Error- if there is anulllistener- See Also:
-
createWinListener
Creates a window-closing listener for the popup.- Parameters:
p- theJPopupMenu- Returns:
- the new window-closing listener
- See Also:
-
getSubElements
Returns an array ofMenuElements containing the submenu for this menu component. If popup menu isnullreturns an empty array. This method is required to conform to theMenuElementinterface. Note that sinceJSeparators do not conform to theMenuElementinterface, this array will only containJMenuItems.- Returns:
- an array of
MenuElementobjects
-
getComponent
Returns thejava.awt.Componentused to paint thisMenuElement. The returned component is used to convert events and detect if an event is inside a menu component. -
doClick
public void doClick(int pressTime) Programmatically performs a "click". This overrides the methodAbstractButton.doClickin order to make the menu pop up.- Overrides:
doClickin classAbstractButton- Parameters:
pressTime- indicates the number of milliseconds the button was pressed for
-
createActionComponent
Factory method which creates theJMenuItemforActions added to theJMenu. As of 1.3, this is no longer the preferred method. Instead it is recommended to configure a control with an action usingsetAction, and then adding that control directly to theContainer.- Parameters:
a- theActionfor the menu item to be added- Returns:
- the new menu item
- Since:
- 1.3
- See Also:
-
createActionChangeListener
Returns a properly configuredPropertyChangeListenerwhich updates the control as changes to theActionoccur. As of 1.3, this is no longer the preferred method for addingActions to aContainer. Instead it is recommended to configure a control with an action usingsetAction, and then add that control directly to theContainer.
-