1-13. Associating Keyboard Sequences to Applications

Problem

You want to create keyboard shortcuts for menu options.

Solution

Create an application that will use JavaFX’s key combination APIs. The main classes you will be using are shown here:

  • javafx.scene.input.KeyCode
  • javafx.scene.input.KeyCodeCombination
  • javafx.scene.input.KeyCombination

The following source code listing is an application that displays the available keyboard shortcuts that are bound to menu items. When the user performs a keyboard shortcut the application will display the key combination on the screen:

        primaryStage.setTitle("Chapter 1-13 Associating Keyboard Sequences");         Group root = new Group();         Scene scene = new Scene(root, 530, 300, Color.WHITE); ...

Get JavaFX 2.0: Introduction by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.