O'Reilly logo

JavaFX 2.0: Introduction by Example by Carl Dea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required