Example program:
package prv.rli.codetest;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class MenuNavigationWithHiddenMenuItem extends Application {
public MenuNavigationWithHiddenMenuItem() {
}
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("Menu navigation with hidden item");
Scene scene = new Scene(new VBox(), 400, 350);
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu("File");
menuBar.getMenus().addAll(menuFile);
menuFile.getItems().addAll(new MenuItem("New"), new MenuItem("Hidden"), new MenuItem("Quit"));
menuFile.getItems().get(1).setVisible(false);
((VBox) scene.getRoot()).getChildren().addAll(menuBar);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
If you start the program, open the File menu and use the <Down>-Key to traverse through the menu items, the focus will cycle like this (with each press of the <Down>-Key):
* New
* New
* Quit
instea of just:
* New
* Quit
Interestingly, if you use <Tab>, things work as expected.
package prv.rli.codetest;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class MenuNavigationWithHiddenMenuItem extends Application {
public MenuNavigationWithHiddenMenuItem() {
}
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("Menu navigation with hidden item");
Scene scene = new Scene(new VBox(), 400, 350);
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu("File");
menuBar.getMenus().addAll(menuFile);
menuFile.getItems().addAll(new MenuItem("New"), new MenuItem("Hidden"), new MenuItem("Quit"));
menuFile.getItems().get(1).setVisible(false);
((VBox) scene.getRoot()).getChildren().addAll(menuBar);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
If you start the program, open the File menu and use the <Down>-Key to traverse through the menu items, the focus will cycle like this (with each press of the <Down>-Key):
* New
* New
* Quit
instea of just:
* New
* Quit
Interestingly, if you use <Tab>, things work as expected.
- relates to
-
JDK-8088768 Keyboard traversal of menubar with hidden menu is broken
-
- Open
-
-
JDK-8087363 MenuItem: Unselectable MenuItem can be invoked by accelerator key(shortcut key)
-
- Closed
-