@@ -121,17 +121,15 @@ public class MenuBarSkin extends SkinBase<MenuBar> {
121
121
* *
122
122
**************************************************************************/
123
123
124
+ /** contains MenuBarButton's children only */
124
125
private final HBox container ;
126
+ /** index of *focused* MenuBarButton */
127
+ private int focusedMenuIndex = -1 ;
125
128
126
129
// represents the currently _open_ menu
127
130
private Menu openMenu ;
128
131
private MenuBarButton openMenuButton ;
129
132
130
- // represents the currently _focused_ menu. If openMenu is non-null, this should equal
131
- // openMenu. If openMenu is null, this can be any menu in the menu bar.
132
- private Menu focusedMenu ;
133
- private int focusedMenuIndex = -1 ;
134
-
135
133
private static WeakHashMap <Stage , Reference <MenuBarSkin >> systemMenuMap ;
136
134
private static List <MenuBase > wrappedDefaultMenus = new ArrayList <>();
137
135
private static Stage currentMenuBarStage ;
@@ -295,7 +293,7 @@ public MenuBarSkin(final MenuBar control) {
295
293
// Key navigation
296
294
sceneListenerHelper .addEventFilter (scene , KeyEvent .KEY_PRESSED , (ev ) -> {
297
295
// process right left and may be tab key events
298
- if (focusedMenu != null ) {
296
+ if (focusedMenuIndex >= 0 ) {
299
297
switch (ev .getCode ()) {
300
298
case LEFT : {
301
299
boolean isRTL = control .getEffectiveNodeOrientation () == NodeOrientation .RIGHT_TO_LEFT ;
@@ -429,7 +427,7 @@ private void showMenu(Menu menu, boolean selectFirstItem) {
429
427
if (!menu .isShowing () && !isMenuEmpty (menu )) {
430
428
if (selectFirstItem ) {
431
429
// put selection / focus on first item in menu
432
- MenuButton menuButton = getNodeForMenu (focusedMenuIndex );
430
+ MenuButton menuButton = menuBarButtonAt (focusedMenuIndex );
433
431
Skin <?> skin = menuButton .getSkin ();
434
432
if (skin instanceof MenuButtonSkinBase ) {
435
433
((MenuButtonSkinBase )skin ).requestFocusOnFirstMenuItem ();
@@ -445,7 +443,6 @@ private void showMenu(Menu menu, boolean selectFirstItem) {
445
443
*/
446
444
void setFocusedMenuIndex (int index ) {
447
445
focusedMenuIndex = (index >= -1 && index < getSkinnable ().getMenus ().size ()) ? index : -1 ;
448
- focusedMenu = (focusedMenuIndex != -1 ) ? getSkinnable ().getMenus ().get (index ) : null ;
449
446
450
447
if (focusedMenuIndex != -1 ) {
451
448
openMenuButton = (MenuBarButton )container .getChildren ().get (focusedMenuIndex );
@@ -733,12 +730,9 @@ public void dispose() {
733
730
* *
734
731
**************************************************************************/
735
732
736
- // For testing purpose only.
737
- MenuButton getNodeForMenu (int i ) {
738
- if (i < container .getChildren ().size ()) {
739
- return (MenuBarButton )container .getChildren ().get (i );
740
- }
741
- return null ;
733
+ // package protected for testing purposes
734
+ MenuBarButton menuBarButtonAt (int i ) {
735
+ return (MenuBarButton )container .getChildren ().get (i );
742
736
}
743
737
744
738
int getFocusedMenuIndex () {
@@ -1083,6 +1077,7 @@ private void menuModeEnd() {
1083
1077
}
1084
1078
1085
1079
private void moveToMenu (Direction dir , boolean doShow ) {
1080
+ Menu focusedMenu = menuBarButtonAt (focusedMenuIndex ).menu ;
1086
1081
boolean showNextMenu = doShow && focusedMenu .isShowing ();
1087
1082
findSibling (dir , focusedMenuIndex ).ifPresent (p -> {
1088
1083
setFocusedMenuIndex (p .getValue ());
0 commit comments