button.setClickShortcut Not Working in 6.6.2

I am trying out Vaadin 6.6.2 for a simple application. The buttons (OK and Cancel) are defined and put into the form footer.

I also define a keyboard shortcut Enter for the OK button, with the setClickShortCut method, but it does not seem to work (no click event is generated when Enter is pressed from the keyboard.

There is a bug (#5341) in earlier version of Vaadin on this problem, which was reportedly fixed. Question is: did I make a mistake in my code, or the bug has resurfaced in Vaadin 6.6.2.

I would appreciate any comments and suggestions. Thank you in advance.

Here is the code:

public LoginWindow (String caption) {

	// Setup window
	if (caption != null) setCaption (caption);
	center();							// for centering window
	VerticalLayout layout = (VerticalLayout) getContent();
	layout.setSizeUndefined();					// for auto-sizing window
	// Setup login form and layout its fields
	form = new Form ();
	form.setCaption ("Please login with your credentials");

	userID = new TextField ("User ID:");
	password = new TextField ("Password:");
	companyID = new TextField ("Company ID:");
	server = new TextField ("Server:");	
	Layout formLayout = form.getLayout();
	formLayout.addComponent (userID);
	formLayout.addComponent (password);
	formLayout.addComponent (companyID);
	formLayout.addComponent (server);		

	// Setup buttons and attach listeners
	HorizontalLayout buttonBar = new HorizontalLayout();
	okButton = new Button ("OK");							
	cancelButton = new Button ("Cancel");


	// Center the buttons
	form.setWidth (null);
	((HorizontalLayout)form.getFooter()).setComponentAlignment(buttonBar, Alignment.MIDDLE_CENTER);

// Define shortcut for ENTER (NOT WORKING!!!)
//okButton.addShortcutListener(new Button.ClickShortcut(okButton, KeyCode.ENTER));
okButton.addStyleName(“primary”); // default style is primary



public void buttonClick (ClickEvent event) {
	if (event.getButton() == okButton) {

	if (event.getButton() == cancelButton) {


I just tested this on Vaadin 6.6.2 using the following simple app:

public class TestApplication extends Application {
    public void init() {
               Window mainWindow = new Window();

        Button b = new Button("Test");
        b.addListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {

        Form form = new Form();
        HorizontalLayout hl = new HorizontalLayout();


The click shortcut seems to work normally with the Button placed in the footer of the Form. Please try this out with your environment and post back if it does not work.


Thanks for the reply and code. I did test it out in my environment and it works.

But still I could not figure out why my code posted above does not work. Eventually, I found out why. The codes as posted for LoginWIndow are fine. The problem lies with the init() method of the main web application class calling the LoginWIndow. The init() method is given below:

public class MyApplication extends Application {

public void init () {
// Setup GUI of the application
mainWindow = new Window(“Webagent”);
Label label = new Label(“Hello user!!”);

//setMainWindow(mainWindow);                            // position A: it works

// Setup login window
loginWindow = new LoginWindow ("Login Now", this);	

setMainWindow(mainWindow);                             // position B: WONT WORK



When the statement setMainWIndow(mainWindow) is at position B, the shortcut key ENTER (when the LoginWindow is active) WONT WORK. However, when the statement is moved from position B to position A , it works fine and a clickevent is generated when ENTER is pressed.

Although the culpit is identified, but I do not undertand why this is so. Could anyone try to explain the difference in the placement of the setMainWIndow(mainWindow) line???

Thank you.


first, it’s nice to hear that you got the problem solved!

I tried a test case with similar code to what you provided and indeed, if the setMainWindow is called at the later point the click shortcut will not work. I’m not exactly sure what is causing this, but it must have something to do with listener registrations, since the click shortcuts are bound to the window.

This is not documented anywhere I could find and I do think it should function with the setMainWindow call in either location. Therefore this is probably a bug in Vaadin. If you have the time, please create a ticket to the
Vaadin trac
and include the code or link to this conversation thread. Thanks!


Hi, Tepi:

Just to let you know that a ticket was submitted on this possible bug. Ticket # is 7567. Thank you.