JavaSwingComponentsMenus: JMenuBar


JMenuBar

JMenuBar

class JMenuBar
    extends JComponent, MenuElement
{
    
}

silly additional Container methods: add(JMenu), getMenu, getMenuCount(=getComponentCount), getComponentAtIndex(=getComponent), getComponentIndex (should be in Container)

set/getBorderPainted (should be in JComponent)

set/getMargin (unsafe)

set/getHelpMenu (unimplemented - actually JMenuBar shouldn't care, a custom LAF may well implement them)

selection model: setSelectionModel, getSelectionModel, isSelected, setSelected (silly, if any, why not the complete set of methods?)

MenuElement:

processMouseEvent, processKeyEvent, menuSelectionChanged: do nothing

getSubElements: all children that are MenuElements

getComponent: this

processKeyBinding overridden to forward to all MenuElement descendants

add/removeNotify register menu bar on KeyboardManager (package private) <- investigate

BasicMenuBarUI

adds ChangeListener to JMenu children models (not dynamically): updates selection model (assumes there always is one selected, does not update when JMenus are removed/added), does not react to selection model changes (i.e selection model practically unsupported except readonly for static situations) (Actually, could addChangeListener to the JMenu itself.)

TakeFocus action: sets selected path to [ menuBar, first menu, first menu's popup ].

Windows TakeFocus action: sets selected path [menuBar, firstMenu ], shows mnemonics.

Synth: essentially copied from Basic

Actually there is almost nothing except for the LayoutManager (which is (now needlessly?) updated on changes of the component orientation), the usual properties and the take-focus (a.k.a. select-first-menu) action (which IMO belongs to the root pane)

Explicit mentioning of JMenu in JMenuBar code

JMenuBar: add(JMenu), getMenu, set/getHelpMenu; accessibility

BasicMenuBarUI: getMenu (for updating selection model); "take focus" action

Accessibility/focus action need to know it is a JMenu as to add its popup menu to the path.

There should be a generic method for this; in the LAF if LAF dependent (ass it seems to be, see Windows).

Usage of JMenuBar

RootPaneContainer/JRootPane: without really caring what it is

JMenu: isTopLevelMenu iff parent is a JMenuBar; menu path guessing stops at a JMenuBar

KeyboardManager: special key event processing (investigate!)

BasicInternalFrameTitlePane: JMenuBar used for system menu; otherwise just as a component

BasicMenuUI: iff parent JMenuBar, PostAction use explicit path, otherwise open the popup only if the menu already is selected (by appending it)

if topLevel (i.e parent JMenuBar), mousePressed/Entered: ...

MotifMenuUI: similar if topLevel

Other uses of isTopLevel in BasicMenuItemUI, BasicMenuUI, BasicPopupMenuUI, other LAFs

BasicPopupMenuUI

MetalBorders

MetalTitlePane: similar to internal frame

MotifBorders, MotifGraphicsUtils

more Synth, Windows

Other components

What happens if non-JMenus are added to a JMenuBar?

The JMenuBar accessible implementation will ignore them, but also not allow to select them (even if they are menu elements).

The BasicMenuItemUI focus action will not activate them (thus if, at first position, do not allow activation). (The SingleSelectionModel chaos will also break more).

WindowsRootPaneUI also has some code that expect the first component to be a JMenu.


(C) 2001-2009 Christian Kaufhold (swing@chka.de)