Book Image

Vaadin 7 Cookbook

Book Image

Vaadin 7 Cookbook

Overview of this book

Table of Contents (19 chapters)
Vaadin 7 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Customizing shortcuts


Some users want to use the mouse as little as possible. They prefer to use the keyboard. For these users, we can improve our application by adding keyboard shortcuts. In this recipe, we will show how to add shortcuts on components in Vaadin's application. We will add two actions. The first action is for saving and the second action is for showing the window with Help.

How to do it...

Carry out the following steps to create custom shortcuts:

  1. Create a Vaadin project with a main UI class named Demo as follows:

    public class Demo extends UI {…}
  2. We create a class called ShortcutPanel which extends the Panel class and implements the Handler interface. We extend the Panel class because the keyboard actions can currently be attached only to Panel and Window.

    public class ShortcutPanel extends Panel implements Handler {…}
  3. At the beginning of the class, we create two objects. The first one is a window for showing Help. This instance is created by a separate method. The second object...