gwt

TabPanel Example

This is an example of how to create a TabPanel example using the Google Web Toolkit, that is an open source set of tools that allows web developers to create and maintain complex JavaScript front-end applications in Java. A TabPanel is a panel that represents a tabbed set of pages, each of which contains another widget. Its child widgets are shown as the user selects the various tabs associated with them. The tabs can contain arbitrary HTML. To create a TabPanel we have performed the following steps:

  • The TabPanelExample class implements the com.google.gwt.core.client.EntryPoint interface to allow the class to act as a module entry point. It overrides its onModuleLoad() method.
  • Create a new Tab Panel. Set some styling to it, such as the size. Add some content and name each Tab of the Tab Panel.
  • Add the TabPanel to the RootPanel, that is the panel to which all other widgets must ultimately be added.

Let’s take a look at the code snippet that follows: 

package com.javacodegeeks.snippets.enterprise;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TabPanel;



public class TabPanelExample implements EntryPoint {

	@Override
	public void onModuleLoad() {
		

  // Create new Tab Panel
		TabPanel tabPanel = new TabPanel();
		

  // Set some styling
  

  tabPanel.setSize("500px", "250px");
		tabPanel.addStyleName("table-center");
		

  // Add some content and name each Tab 
		tabPanel.add(new HTML("Tab0 Contents"),"Tab0");
		tabPanel.add(new HTML("Tab1 Contents"),"Tab1");
		tabPanel.add(new HTML("Tab2 Contents"),"Tab2");
		tabPanel.add(new HTML("Tab3 Contents"),"Tab3");
		

  // Set default Tab view on page load
		tabPanel.selectTab(1);


  // Add Tab Panel to Root Panel
		RootPanel.get().add(tabPanel);
	}
}

 
This was an example of how to create a TabPanel example.

Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button