Class JDropDownButton

All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, SwingConstants
Direct Known Subclasses:
ColorChooserButton

public class JDropDownButton extends JButton
Author:
Taha BEN SALAH (taha.bensalah@gmail.com) %creationtime 13 juil. 2006 22:14:21
See Also:
  • Field Details

  • Constructor Details

    • JDropDownButton

      public JDropDownButton()
    • JDropDownButton

      public JDropDownButton(Action a)
    • JDropDownButton

      public JDropDownButton(Icon icon)
    • JDropDownButton

      public JDropDownButton(String text)
    • JDropDownButton

      public JDropDownButton(String text, Icon icon)
  • Method Details

    • getQuickActionDelay

      public int getQuickActionDelay()
    • setQuickActionDelay

      public void setQuickActionDelay(int quickActionDelay)
    • isPaintHandle

      public boolean isPaintHandle()
    • setPaintHandle

      public JDropDownButton setPaintHandle(boolean paintHandle)
    • installAncestorListener

      protected void installAncestorListener()
    • hidePopup

      public void hidePopup()
      Causes the combo box to close its popup window.
    • getTreeMenuItemByActionCommand

      public JMenuItem getTreeMenuItemByActionCommand(String type)
    • addQuickActionListener

      public void addQuickActionListener(ActionListener listener)
    • removeQuickActionListener

      public void removeQuickActionListener(ActionListener listener)
    • fireQuickActionPerformed

      protected void fireQuickActionPerformed(ActionEvent event)
    • getPopupOrientation

      public int getPopupOrientation()
    • setPopupOrientation

      public void setPopupOrientation(int orientation)
      Parameters:
      orientation - : SwingConstants.LEFT or SwingConstants.RIGHT
    • paintHandle

      public void paintHandle(Graphics g)
    • paintComponent

      protected void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • paintTriangle

      public void paintTriangle(Graphics g, int x, int y, int size, int direction, boolean isEnabled)
    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JButton
    • 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

      protected Point getPopupMenuOrigin()
      Computes the origin for the JMenu's popup menu. This method uses Look and Feel properties named Menu.menuPopupOffsetX, Menu.menuPopupOffsetY, Menu.submenuPopupOffsetX, and Menu.submenuPopupOffsetY to adjust the exact location of popup.
      Returns:
      a Point in the coordinate space of the menu which should be used as the origin of the JMenu'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 the delay property. In most cases, the delay is not observed for top level menus or while dragging. The default for delay is 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 delay property
    • setDelay

      public void setDelay(int d)
      Sets the suggested delay before the menu's PopupMenu is 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 - if d is 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 position
      y - the y coordinate of the popup's new position
    • add

      public JMenuItem add(JMenuItem menuItem)
      Appends a menu item to the end of this menu. Returns the menu item added.
      Parameters:
      menuItem - the JMenuitem to be added
      Returns:
      the JMenuItem added
    • add

      public Component add(Component c)
      Appends a component to the end of this menu. Returns the component added.
      Overrides:
      add in class Container
      Parameters:
      c - the Component to add
      Returns:
      the Component added
    • add

      public Component add(Component c, int index)
      Adds the specified component to this container at the given position. If index equals -1, the component will be appended to the end.
      Overrides:
      add in class Container
      Parameters:
      c - the Component to add
      index - the position at which to insert the component
      Returns:
      the Component added
      See Also:
    • remove

      public void remove(int pos)
      Removes the menu item at the specified index from this menu.
      Overrides:
      remove in class Container
      Parameters:
      pos - the position of the item to be removed
      Throws:
      IllegalArgumentException - if the value of pos < 0, or if pos is greater than the number of menu items
    • remove

      public void remove(Component c)
      Removes the component c from this menu.
      Overrides:
      remove in class Container
      Parameters:
      c - the component to be removed
    • removeAll

      public void removeAll()
      Removes all menu items from this menu.
      Overrides:
      removeAll in class Container
    • add

      public JMenuItem add(String s)
      Creates a new menu item with the specified text and appends it to the end of this menu.
      Parameters:
      s - the string for the menu item to be added
    • add

      public JMenuItem add(Action a)
      Creates a new menu item attached to the specified Action object and appends it to the end of this menu. As of 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.
      Parameters:
      a - the Action for the menu item to be added
      See Also:
    • addSeparator

      public void addSeparator()
      Appends a new separator to the end of the menu.
    • insert

      public void insert(String s, int pos)
      Inserts a new menu item with the specified text at a given position.
      Parameters:
      s - the text for the menu item to add
      pos - an integer specifying the position at which to add the new menu item
      Throws:
      IllegalArgumentException - when the value of pos < 0
    • insert

      public JMenuItem insert(JMenuItem mi, int pos)
      Inserts the specified JMenuitem at a given position.
      Parameters:
      mi - the JMenuitem to add
      pos - an integer specifying the position at which to add the new JMenuitem
      Returns:
      the new menu item
      Throws:
      IllegalArgumentException - if the value of pos < 0
    • insert

      public JMenuItem insert(Action a, int pos)
      Inserts a new menu item attached to the specified Action object at a given position.
      Parameters:
      a - the Action object for the menu item to add
      pos - an integer specifying the position at which to add the new menu item
      Throws:
      IllegalArgumentException - if the value of pos < 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 of index < 0
    • getItem

      public JMenuItem getItem(int pos)
      Returns the JMenuItem at the specified position. If the component at pos is not a menu item, null is returned. This method is included for AWT compatibility.
      Parameters:
      pos - an integer specifying the position
      Returns:
      the menu item at the specified position; or null if the item as the specified position is not a menu item
      Throws:
      IllegalArgumentException - if the value of pos < 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

      public void remove(JMenuItem item)
      Removes the specified menu item from this menu. If there is no popup menu, this method will have no effect.
      Parameters:
      item - the JMenuItem to 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

      public Component getMenuComponent(int n)
      Returns the component at position n.
      Parameters:
      n - the position of the component to be returned
      Returns:
      the component requested, or null if there is no popup menu
    • getMenuComponents

      public Component[] getMenuComponents()
      Returns an array of Components of the menu's subcomponents. Note that this returns all Components in the popup menu, including separators.
      Returns:
      an array of Components or an empty array if there is no popup menu
    • isMenuComponent

      public boolean isMenuComponent(Component c)
      Returns true if the specified component exists in the submenu hierarchy.
      Parameters:
      c - the Component to be tested
      Returns:
      true if the Component exists, false otherwise
    • getPopupMenu

      public JPopupMenu getPopupMenu()
      Returns the popupmenu associated with this menu. If there is no popupmenu, it will create one.
    • getPopupMenuOrNull

      public JPopupMenu getPopupMenuOrNull()
    • addMenuListener

      public void addMenuListener(MenuListener l)
      Adds a listener for menu events.
      Parameters:
      l - the listener to be added
    • removeMenuListener

      public void removeMenuListener(MenuListener l)
      Removes a listener for menu events.
      Parameters:
      l - the listener to be removed
    • getMenuListeners

      public MenuListener[] getMenuListeners()
      Returns an array of all the MenuListeners 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 a null listener
      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 a null listener
      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 a null listener
      See Also:
    • createWinListener

      protected JDropDownButton.WinListener createWinListener(JPopupMenu p)
      Creates a window-closing listener for the popup.
      Parameters:
      p - the JPopupMenu
      Returns:
      the new window-closing listener
      See Also:
    • getSubElements

      public MenuElement[] getSubElements()
      Returns an array of MenuElements containing the submenu for this menu component. If popup menu is null returns an empty array. This method is required to conform to the MenuElement interface. Note that since JSeparators do not conform to the MenuElement interface, this array will only contain JMenuItems.
      Returns:
      an array of MenuElement objects
    • getComponent

      public Component getComponent()
      Returns the java.awt.Component used to paint this MenuElement. 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 method AbstractButton.doClick in order to make the menu pop up.
      Overrides:
      doClick in class AbstractButton
      Parameters:
      pressTime - indicates the number of milliseconds the button was pressed for
    • createActionComponent

      protected JMenuItem createActionComponent(Action a)
      Factory method which creates the JMenuItem for Actions added to the JMenu. As of 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.
      Parameters:
      a - the Action for the menu item to be added
      Returns:
      the new menu item
      Since:
      1.3
      See Also:
    • createActionChangeListener

      protected PropertyChangeListener createActionChangeListener(JMenuItem b)
      Returns a properly configured PropertyChangeListener which updates the control as changes to the Action occur. As of 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.