最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - How to create a Ctrl+Shift+SOMEKEY accelerator in JavaFX? - Stack Overflow

programmeradmin1浏览0评论

I need a Ctrl+Shift+S accelerator for a menu item. However, the accelerator I created doesn't work. This is my code:

public class NewMain extends Application {

    @Override
    public void start(Stage stage) {
        MenuBar menuBar = new MenuBar();
        Menu fileMenu = new Menu("File");

        MenuItem fooItem = new MenuItem("Foo");
        fooItem.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
        fooItem.setOnAction(e -> System.out.println("Ctrl+Shift+S triggered"));

        MenuItem barItem = new MenuItem("Bar");
        barItem.setAccelerator(new KeyCodeCombination(KeyCode.A, KeyCombination.CONTROL_DOWN));
        barItem.setOnAction(e -> System.out.println("Ctrl+A triggered"));

        fileMenu.getItems().addAll(fooItem, barItem);
        menuBar.getMenus().add(fileMenu);

        BorderPane root = new BorderPane();
        root.setTop(menuBar);
        Scene scene = new Scene(root, 400, 300);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

If you run the code you will see that Ctrl+A works, but Ctrl+Shift+S doesn't.

Could anyone say how to fix it?

发布评论

评论列表(0)

  1. 暂无评论