Free Data Structures and Algorithms Course

Subscribe below and get all best seller courses for free !!!


Subscribe to all free courses

How to implement Tabbed Pane in a Frame using Java Swing API ?.

A Simple program to demonstrate how to use Tabbed Pane in a Frame using Java Swing API ?.

package com.iplt20.swing.example;

import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class TabbedPaneDemo extends JFrame {
  private String[] ipl = {
  "Deccan Chargers", "Kolkata Night Riders", 
  "Mumbai Indians", "Chennai Super Kings", 
  "Rajasthan Royals", "Royal Challengers Bangalore",
  "Kings XI Punjab", "Pune Warriors India",
  "Delhi Daredevils"

  private JTabbedPane tab = new JTabbedPane();
  private JTextField textfield = new JTextField(20);
  public TabbedPaneDemo() {
    int i = 0;
    for(String teams : ipl){
      new JTextField("Who will win IPL this year?."));

    tab.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
 textfield.setText("You selected: " +
    add(BorderLayout.SOUTH, textfield);
  public static void main(String[] args) {
  setFrame(new TabbedPaneDemo(), 450, 175);

  public static void 
  setFrame(final JFrame frame, final int width, final int height) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
 frame.setSize(width, height);

Output of the program :

© 2021 Learn Java by Examples Template by Hubberspot