Home Java Example Java Swing Creating a JTabbedPane Container in Java Swing



Creating a JTabbedPane Container in Java Swing
Posted on: April 14, 2007 at 12:00 AM
In this section, you will learn how to create the JTabbedPane container in Java Swing.

Creating a JTabbedPane Container in Java Swing

     

In this section, you will learn how to create the JTabbedPane container in Java Swing. The example for illustration is given in which, all the things related to the creation of JTabbedPane container have been illustrated in efficient manner.

This program has used various tools of swing to implement the JTabbed component of Java. The following figure shows the JTabbedPane component of Java Swing:

Swing JTabbed Pane Component

These are explained as follows:

JTabbedPane:
This is the class of javax.swing.*; package which creates the JTabbedPane component of Java Swing which contains separate button for the separate tab. You can also container component with the specific tab.

add():
This is the method of JTabbedPane class which is used to add container component to the JTabbedPane component of Java Swing. This method takes different-different types of arguments but in this program this method has taken two argument, first is the title for the tab and another is the component name which is specified for a particular tab to show for that.

Here is the code of the program:

import javax.swing.*;
import java.awt.*;

public class CreateTabbedPane{
  public static void main(String[] args){
  JFrame frame = new JFrame("Tabbed Pane Frame");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  JTabbedPane tab = new JTabbedPane();
  frame.add(tab, BorderLayout.CENTER);
  JButton button = new JButton("1");
  tab.add("Tab 1", button);
  button = new JButton("2");
  tab.add("Tab 2", button);
  frame.setSize(400,400);
  frame.setVisible(true);
  }
}

Download this example.

Related Tags for Creating a JTabbedPane Container in Java Swing:
cideselectiovithisidaicreatetabcontainerforieexamplectetocreationexamjtaciselectedeilffidessectionjtabbedpanemanintabbedmnttrthinjesallillustrationproratepanrelxawhichxampseeatpaneratiolateishallivmpleaandannstrrelatessthavstabatipleplprndono


More Tutorials from this section

Ask Questions?    Discuss: Creating a JTabbedPane Container in Java Swing   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.