Loading...
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.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

TabSheet '+' Button to add new Tabs

P h
5 years ago Aug 18, 2016 8:00am
Olli Tietäväinen
5 years ago Aug 18, 2016 8:41am

Hi,

sure, I can think of a couple of ways to do that. First option would be something like follows:
1) Create a tab with the caption "+" and an empty VerticalLayout as the content
2) Add a listener with addSelectedTabChangeListener
3) In the listener, get the selected tab's content with event.getTabSheet().getSelectedTab() (note: despite the name, this returns the contents of the tab, not the tab object)
4) If the content is an empty VerticalLayout, add some component(s) to the newly opened tab. Then change the caption and add a new tab with the caption "+" and set its contents to an empty layout

The second option would be to use a button instead of a tabsheet. Wrap the button and the tabsheet with an AbsoluteLayout so you can place it over the tabsheet where you want. Add new tabs in the button's click handler and use styles to make the button look like what you want.

Hope these are enough to get you started,
Olli 

 

Volodymyr Horodetskyi
3 years ago Aug 15, 2018 2:04pm
Volodymyr Horodetskyi
3 years ago Aug 15, 2018 2:10pm
Olli Tietäväinen
3 years ago Aug 15, 2018 2:33pm

Use tabSheet.getTab with the index of the tab instead of getSelectedTab() - the latter returns the contents of the selected tab (because of historical reasons).

Volodymyr Horodetskyi
3 years ago Aug 15, 2018 3:19pm
Olli Tietäväinen
3 years ago Aug 16, 2018 5:29am
Volodymyr Horodetskyi
3 years ago Aug 16, 2018 8:24am
Olli Tietäväinen
3 years ago Aug 16, 2018 8:25am