Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Vaadin FocusShortcut between button and window
Hi all,
I have a Window class and my normal UI class. In the UI class I have a button which opens a window. Now I want to add shortcuts. ENTER for ButtonClick and DELETE to close the Window. This works so far but I need to click the window with my mouse before the DELTE button works. I tried to solve this problem by adding FocusShortcuts and it works great for the button but it doesn't work for the window. So how can I change the focus from the button to the window with a shortcut?
My UI class code:
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
Button button = new Button("Orderbuch öffnen");
button.addClickListener(new ClickListener() {
public void buttonClick(Button.ClickEvent event) {
Fenster sub = new Fenster();
// Add it to the root component
UI.getCurrent().addWindow(sub);
}
});
// Shortcut to click the button
button.addShortcutListener(new AbstractField.FocusShortcut(button, KeyCode.B));
button.setClickShortcut(KeyCode.ENTER);
layout.addComponents(button);
layout.setMargin(true);
layout.setSpacing(true);
setContent(layout);
}
My window class code:
public class Fenster extends Window {
public Fenster() {
// Shortcut to close window
addShortcutListener(new AbstractField.FocusShortcut(this, KeyCode.F));
addCloseShortcut(KeyCode.DELETE);
content.setMargin(true);
setContent(content);
}
}
Hi ,
If you try setting focus explicitely to a default component in your window or to the window using setfocus it should work !