Skip to main content

Change components in TabbedPane

2 replies [Last post]
spint
Offline
Joined: 2008-06-17

Is there a way to add a Component to a tab only after it has been selected (on selectionChanged event)?

My application has 7 tabs with different components on each and I don't want to create all the components for each tab when I add it. I just want to create the component when a user selects the tab.

So two possible changes would be.

TabbedPane.addTab(title, icon, null); // allow null component
TabbedPane.setTabComponent(index, component); // call on selectionChanged event

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Shai Almog

Hi,
sure... well sort of ;-)
You can add empty containers to all the tabs (which take no memory at
all). You can then add a tab selection listener which in invoked on
selection and can build the content of the tab lazily.
See: addTabsListener(SelectionListener);

Thanks.

> Is there a way to add a Component to a tab only after it has been
> selected (on selectionChanged event)?
>
> My application has 7 tabs with different components on each and I
> don't want to create all the components for each tab when I add it.
> I just want to create the component when a user selects the tab.
>
> So two possible changes would be.
>
> TabbedPane.addTab(title, icon, null); // allow null component
> TabbedPane.setTabComponent(index, component); // call on
> selectionChanged event
> [Message sent by forum member 'spint' (spint)]
>
> http://forums.java.net/jive/thread.jspa?messageID=287693
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

spint
Offline
Joined: 2008-06-17

That appears to work.

Thanks!