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.
Focus on TextField inside of Tab
Hi all,
I have a TabSheet with two Tabs inside Window. Both of Tabs have VerticalLayout and some TextFields inside. What I want is to focus on the first TextField inside the first Tab when the Window shows up. What I was trying to do was sth like :
firstTab.setDefaultFocusComponent(firstField);
myTabSheet.setSelectedTab(firstTab);
firstField.focus();
but the problem is it works like: when the Window is openned, there's no focus (or the focus on the first tab, I acctually don't know) and then when I press TAB two times then I have focus on the first first inside the first Tab.
Also when I change Tab by clicking on the second Tab, and go back to the first Tab I have what I want : focus on the first field.
What can I do, to set focus on the first field inside first Tab when the Window appears ?
Thanks all, regards
Hi Dominik,
I had the same issue you had and I couldn't solve. It's weird that if we change to tab 1 and then tab 2, we get the behavior we want.
TextField firstField = new TextField();
VerticalLayout firstTab = new VerticalLayout(firstField,
new TextField());
firstTab.setCaption("First");
VerticalLayout secondTab = new VerticalLayout();
secondTab.setCaption("Second");
TabSheet tabSheet = new TabSheet(firstTab, secondTab);
tabSheet.setImmediate(true);
tabSheet.getTab(0).setDefaultFocusComponent(firstField);
Window window = new Window();
window.setContent(tabSheet);
window.setSizeFull();
UI.getCurrent().addWindow(window);
[b] tabSheet.setSelectedTab(1);
tabSheet.setSelectedTab(0);[/b]