String : Tabded Pane

Java has class javax.swing.JTabbedPane that is used to represent the tabbed pane. Tabbed pane is a container that has the more than one Panel attached with the tabbed name, where you can place the components. Each tabbed have their own components properties.


You create tabs to JTabbedPane using the addTab( ). Each tab may contain other components.

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

class TabbedPaneDemo
{
    public static void main(String ar[])
    {
        JFrame frame=new JFrame("Menus");
        
        JTabbedPane tp=new JTabbedPane();
        
        JPanel p1=new JPanel();
        p1.setBackground(Color.yellow);
        
        JPanel p2=new JPanel();
        p2.setBackground(Color.blue);
        
        JPanel p3=new JPanel();
        p3.setBackground(Color.gray);
        
        tp.addTab("Panel 1",p1);
        tp.addTab("Panel 2",p2);
        tp.addTab("Panel 3",p3);
        
        frame.add(tp);
        frame.setBounds(200,100,400,300);
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        frame.setVisible(true);

    }
}

No comments:

Popular Posts