JIDE 3.5.15

com.jidesoft.swing
Class JideMenu

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.AbstractButton
                  extended by javax.swing.JMenuItem
                      extended by javax.swing.JMenu
                          extended by com.jidesoft.swing.JideMenu
All Implemented Interfaces:
Alignable, ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, MenuElement, SwingConstants
Direct Known Subclasses:
Chevron, JideSplitButton

public class JideMenu
extends JMenu
implements Alignable

A special implementation of JMenu. It is used to replace JMenu in order to use with CommandBar.
It has two special features. First, it has a PopupMenuCustomizer for lazy menu creation. Instead of creating menu upfront which might be quite expensive, you can create it using PopupMenuCustomizer. PopupMenuCustomizer is called before the menu is set visible. Please note, when you use PopupMenuCustomizer, you need to remove the old menu items you added previously using PopupMenuCustomizer. Otherwise, you will see a menu which gets longer and longer when you show it. See below for an example.

 JideMenu jideMenu = new JideMenu("Dynamic");
 jideMenu.setPopupMenuCustomizer(new JideMenu.PopupMenuCustomizer(){
     public void customize(JPopupMenu menu) {
         menu.add("item 1");
         menu.add("item 2");
         menu.add("item 3");
         menu.add("item 4");
         menu.add("item 5");
     }
 });
 

Second feature is popup alignment. Usually menu and its popup align to the left side. In our case, we hope they align to right side. So we added a method call setPreferredPopupHorizontalAlignment(). You can set to RIGHT if you want to.

See Also:
Serialized Form

Nested Class Summary
static interface JideMenu.MenuCreator
          Deprecated. The createMenu method of MenuCreator should JPopupMenu as parameter. Since it's a public API we have to deprecated this one and ask users to use JideMenu.PopupMenuCustomizer instead.
static interface JideMenu.PopupMenuCustomizer
          Customizes the popup menu.
static interface JideMenu.PopupMenuOriginCalculator
          Calculates the origin of the popup menu if specified.
 
Nested classes/interfaces inherited from class javax.swing.JMenu
JMenu.AccessibleJMenu, JMenu.WinListener
 
Nested classes/interfaces inherited from class javax.swing.JMenuItem
JMenuItem.AccessibleJMenuItem
 
Nested classes/interfaces inherited from class javax.swing.AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int DELAY
           
 
Fields inherited from class javax.swing.JMenu
popupListener
 
Fields inherited from class javax.swing.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_PROPERTY
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface com.jidesoft.swing.Alignable
PROPERTY_ORIENTATION
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JideMenu()
           
JideMenu(Action a)
           
JideMenu(String s)
           
JideMenu(String s, boolean b)
           
 
Method Summary
 JideMenu.MenuCreator getMenuCreator()
          Deprecated. useJideMenu.PopupMenuCustomizer and getPopupMenuCustomizer() instead.
 int getOrientation()
          Gets the orientation.
 JideMenu.PopupMenuOriginCalculator getOriginCalculator()
          Gets the PopupMenuOriginCalculator or null, if none has been specified.
 JideMenu.PopupMenuCustomizer getPopupMenuCustomizer()
          Gets the PopupMenuCustomizer.
protected  Point getPopupMenuOrigin()
           
 int getPreferredPopupHorizontalAlignment()
           
 int getPreferredPopupVerticalAlignment()
           
protected  void hideMenu()
           
protected  void initMenu()
           
 boolean isOpaque()
          Checks if the
 boolean isTopLevelMenu()
          Checks if the menu is added to a top level menu container.
 boolean originalIsOpaque()
           
 void setMenuCreator(JideMenu.MenuCreator menuCreator)
          Deprecated. useJideMenu.PopupMenuCustomizer and setPopupMenuCustomizer(com.jidesoft.swing.JideMenu.PopupMenuCustomizer) instead.
 void setOrientation(int orientation)
          Changes the orientation.
 void setOriginCalculator(JideMenu.PopupMenuOriginCalculator originCalculator)
          Sets the PopupMenuOriginCalculator that will be used to determine the popup menu origin.
 void setPopupMenuCustomizer(JideMenu.PopupMenuCustomizer customizer)
          Sets the PopupMenuCustomizer.
 void setPopupMenuVisible(boolean b)
           
 void setPreferredPopupHorizontalAlignment(int preferredPopupHorizontalAlignment)
           
 void setPreferredPopupVerticalAlignment(int preferredPopupVerticalAlignment)
           
protected  boolean shouldHidePopupMenu()
          Check if the popup menu should stay hidden although setPopupMenuVisible(boolean) is invoked.
 boolean supportHorizontalOrientation()
          Checks if the component support horizontal orientation.
 boolean supportVerticalOrientation()
          Checks if the component support vertical orientation.
 
Methods inherited from class javax.swing.JMenu
add, add, add, add, add, addMenuListener, addSeparator, applyComponentOrientation, createActionChangeListener, createActionComponent, createWinListener, doClick, fireMenuCanceled, fireMenuDeselected, fireMenuSelected, getAccessibleContext, getComponent, getDelay, getItem, getItemCount, getMenuComponent, getMenuComponentCount, getMenuComponents, getMenuListeners, getPopupMenu, getSubElements, getUIClassID, insert, insert, insert, insertSeparator, isMenuComponent, isPopupMenuVisible, isSelected, isTearOff, menuSelectionChanged, paramString, processKeyEvent, remove, remove, remove, removeAll, removeMenuListener, setAccelerator, setComponentOrientation, setDelay, setMenuLocation, setModel, setSelected, updateUI
 
Methods inherited from class javax.swing.JMenuItem
actionPropertyChanged, addMenuDragMouseListener, addMenuKeyListener, configurePropertiesFromAction, fireMenuDragMouseDragged, fireMenuDragMouseEntered, fireMenuDragMouseExited, fireMenuDragMouseReleased, fireMenuKeyPressed, fireMenuKeyReleased, fireMenuKeyTyped, getAccelerator, getMenuDragMouseListeners, getMenuKeyListeners, init, isArmed, processKeyEvent, processMenuDragMouseEvent, processMenuKeyEvent, processMouseEvent, removeMenuDragMouseListener, removeMenuKeyListener, setArmed, setEnabled, setUI
 
Methods inherited from class javax.swing.AbstractButton
addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, 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, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, paintBorder, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
Methods inherited from class javax.swing.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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, 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, update
 
Methods inherited from class java.awt.Container
add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, 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, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.swing.MenuElement
processKeyEvent, processMouseEvent
 

Field Detail

DELAY

public static int DELAY
Constructor Detail

JideMenu

public JideMenu()

JideMenu

public JideMenu(String s)

JideMenu

public JideMenu(Action a)

JideMenu

public JideMenu(String s,
                boolean b)
Method Detail

initMenu

protected void initMenu()

isTopLevelMenu

public boolean isTopLevelMenu()
Checks if the menu is added to a top level menu container. It will be consider as top level menu when
1. getParent() equals null, or
2. getParent() is not an instance of JPopupMenu
Please note, the definition of topLevelMenu is different from that of JMenu.

Overrides:
isTopLevelMenu in class JMenu
Returns:
true if it's top level menu.

getOriginCalculator

public JideMenu.PopupMenuOriginCalculator getOriginCalculator()
Gets the PopupMenuOriginCalculator or null, if none has been specified.

Returns:
the calculator

setOriginCalculator

public void setOriginCalculator(JideMenu.PopupMenuOriginCalculator originCalculator)
Sets the PopupMenuOriginCalculator that will be used to determine the popup menu origin.

Parameters:
originCalculator - the calculator

getMenuCreator

@Deprecated
public JideMenu.MenuCreator getMenuCreator()
Deprecated. useJideMenu.PopupMenuCustomizer and getPopupMenuCustomizer() instead.

Gets the MenuCreator.

Returns:
the MenuCreator.

setMenuCreator

@Deprecated
public void setMenuCreator(JideMenu.MenuCreator menuCreator)
Deprecated. useJideMenu.PopupMenuCustomizer and setPopupMenuCustomizer(com.jidesoft.swing.JideMenu.PopupMenuCustomizer) instead.

Sets the MenuCreator. MenuCreator can be used to do lazy menu creation. If you put code in the MenuCreator, it won't be called until before the menu is set visible.

Parameters:
menuCreator - he menu creator

getPopupMenuCustomizer

public JideMenu.PopupMenuCustomizer getPopupMenuCustomizer()
Gets the PopupMenuCustomizer.

Returns:
the PopupMenuCustomizer.

setPopupMenuCustomizer

public void setPopupMenuCustomizer(JideMenu.PopupMenuCustomizer customizer)
Sets the PopupMenuCustomizer. PopupMenuCustomizer can be used to do lazy menu creation. If you put code in the MenuCreator, it won't be called until before the menu is set visible.

PopupMenuCustomizer has a customize method. The popup menu of this menu will be passed in. You can add/remove/change the menu items in customize method. For example, instead of

 JideMenu menu = new JideMenu();
 menu.add(new JMenuItem("..."));
 menu.add(new JMenuItem("..."));
 
You can do
 JideMenu menu = new JideMenu();
 menu.setPopupMenuCustomzier(new JideMenu.PopupMenuCustomizer() {
     void customize(JPopupMenu popupMenu) {
         poupMenu.removeAll();
         popupMenu.add(new JMenuItem("..."));
         popupMenu.add(new JMenuItem("..."));
     }
 }
 
If the menu is never used, the two add methods will never be called thus improve the performance.

Parameters:
customizer - the popup menu customizer

getPopupMenuOrigin

protected Point getPopupMenuOrigin()
Overrides:
getPopupMenuOrigin in class JMenu

isOpaque

public boolean isOpaque()
Checks if the

Overrides:
isOpaque in class JComponent
Returns:
false if it's top level menu. Otherwise, it will return what super.isOpaque().

originalIsOpaque

public boolean originalIsOpaque()

hideMenu

protected void hideMenu()

getPreferredPopupHorizontalAlignment

public int getPreferredPopupHorizontalAlignment()

setPreferredPopupHorizontalAlignment

public void setPreferredPopupHorizontalAlignment(int preferredPopupHorizontalAlignment)

getPreferredPopupVerticalAlignment

public int getPreferredPopupVerticalAlignment()

setPreferredPopupVerticalAlignment

public void setPreferredPopupVerticalAlignment(int preferredPopupVerticalAlignment)

supportVerticalOrientation

public boolean supportVerticalOrientation()
Description copied from interface: Alignable
Checks if the component support vertical orientation. doesn't consider the component orientation, it should return false.

Specified by:
supportVerticalOrientation in interface Alignable
Returns:
true if it supports vertical orientation

supportHorizontalOrientation

public boolean supportHorizontalOrientation()
Description copied from interface: Alignable
Checks if the component support horizontal orientation.

Specified by:
supportHorizontalOrientation in interface Alignable
Returns:
true if it supports horizontal orientation

setOrientation

public void setOrientation(int orientation)
Description copied from interface: Alignable
Changes the orientation. If the component is a Swing component, the default implementation is this.
JideSwingUtilities.setOrientationOf(this, orientation);

Specified by:
setOrientation in interface Alignable
Parameters:
orientation - the new orientation

getOrientation

public int getOrientation()
Description copied from interface: Alignable
Gets the orientation. If the component is a Swing component, the default implementation is this.
return JideSwingUtilities.getOrientationOf(this);

Specified by:
getOrientation in interface Alignable
Returns:
orientation

setPopupMenuVisible

public void setPopupMenuVisible(boolean b)
Overrides:
setPopupMenuVisible in class JMenu

shouldHidePopupMenu

protected boolean shouldHidePopupMenu()
Check if the popup menu should stay hidden although setPopupMenuVisible(boolean) is invoked.

The default implementation is to check if it contains any menu items. You could override this method to change the default behavior.

Returns:
true if the popup menu should stay invisible. Otherwise false.

JIDE 3.5.15