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

Related Tutorials


 
 

Share on Google+Share on Google+

Creating a JTabbedPane Container in Java Swing

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

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 14, 2007

Related Tutorials

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

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:6
sravan
June 15, 2011
JTabbedPane

how to create JTabbedPane in JTabbedPane.
Atmaram
February 20, 2012
desinging JTab

how to divide JTabb's panel in two vertical part......
bish
January 11, 2012
tabbed panel

help me to create two tabs in different class and the two tabs appear in same frame
tester
January 14, 2012
tabbedpane in jframe

i have created jpanels and adding them to the tabbed pane, i have set the bounds of components like textfield button etc in the panels but its not getting applied in the frame...if you know anything about this pls mail me to test.tracker111@gmail.com
dfg
October 9, 2012
gfdg

great job done...man!!
anon
July 2, 2013
thanks

thanks
DMCA.com