How to set selected tab in tabsheet component

I am using tabsheets with several tabs

like in the screen shot
http://myy.haaga-helia.fi/~a0502671/tabsheet

now i want to be able to set any of these tabs to be default, example tab1, or tab2 or tab 3.

How can i do that?

here is my code


package userInterface;

import com.itmill.toolkit.terminal.ThemeResource;
import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.CustomComponent;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.TabSheet;
import com.itmill.toolkit.ui.Window;
import com.itmill.toolkit.ui.Button.ClickEvent;

public class SystemUserContentClass extends CustomComponent implements Button.ClickListener
{
	Window main;
	private TabSheet tabSystemUser = new TabSheet();
	private Label label = new Label("Employees");
	public SystemUserContentClass(Window mainWindow)
	{
		main = mainWindow;				
	
		tabSystemUser.getSize().setHeight(480);
		tabSystemUser.addTab(new ManageEmployeeClass(), "Employees", null);
		tabSystemUser.addTab(new editEmployeeClass(), "Manage employees",null);
		tabSystemUser.addTab(label, "manage users", new ThemeResource("icons/user_add.png"));
		tabSystemUser.setSelectedTab(new editEmployeeClass());
		setCompositionRoot(tabSystemUser);
		
	}
	
	@Override
	public void buttonClick(ClickEvent event)
	{
		
		
	}

}

in case the image doesnt show…here is the link

http://myy.haaga-helia.fi/~a0502671/tabsheet/

You need to setSelectedTab() using the same instance that you have added to the tabsheet (“new” creates a new instance, so you can’t say “new SomeComponent()” in both addTab() and setSelectedTab()).

…did that make any sense?

Modified code:

Thumbs up!

it works fine…

thanks.

Hi!

I would like also to select a tab, but with a button located in a component already contained in the tabsheet. Example with the following code: on panel 2, there is a button and by clicking on it, I would like to display panel 3. The page is displayed correctly, but the tab in the tab bar is not selected. Is there something wrong or missing? ver 5.2.0rc8

public class TestWindow extends Window {

        private TabSheet ts;
        private Panel p3;
	
	public TestWindow() {

		ts = new TabSheet();
		Panel p1 = new Panel("panel 1");
		Panel p2 = new Panel("panel 2");
		p3 = new Panel("panel 3");
		ts.addTab(p1);
		ts.addTab(p2);
		ts.addTab(p3);
		
		ts.setSelectedTab(p2);
		
		addComponent(ts);

		Button b = new Button("go to panel 3");
		b.addListener(new ClickListener() {
			public void buttonClick(ClickEvent event) {
				goToPanel3();
			}
		});
		p2.addComponent(b);
		
	}

	protected void goToPanel3() {
		ts.setSelectedTab(p3);
	}
		
}

Sylvain

In my opition you code looks correct. This must be a bug. Please send a ticket (with your code attached to it) and we’ll fix it asap.

It has already been fixed with the ticket 1726. I didn’t realize it was exactly same problem :roll:

Thanks!

Sylvain

setSelectedTab still does not work with 5.2.14…

Hi,

I just tested the setSelectedTab example from this thread in 5.2.15 and it seems to work fine. What problem are you experiencing with setSelectedTab?

Best regards,
Artur

Can I switch multiple tabs with Back and Next buttons?