Click here to Skip to main content
Licence CPOL
First Posted 17 Apr 2002
Views 105,552
Downloads 1,728
Bookmarked 16 times

Tab Control in Java ( in AWT)

By | 7 Jun 2010 | Article
This is a Java tab Control like SS Tab in VB. Its Cool One

Sample Image - tabcontrol.gif

Introduction

Dear friends, this is one of most useful components in the Java programming world. Here, I am using the Card Layout for developing this component. Download the project files and run the run.bat file to get the output.

Explanation

The Following files are used in the Tab Control.

  • Border.java, BorderPanel.java, Scrollbar.java are used to create a customized scroll bar.
  • Scrollpanel.java is used to embed a customized scroll bar into a Panel.
  • TabPanel.java is used to create tabs.
  • chatClient1.java is the main applet

Source Code

Here is the source code for setting a Tab Panel:

import java.awt.Panel;
import java.awt.CardLayout;
import java.awt.BorderLayout;
import java.awt.*;
import java.awt.event.*;

public class TapPanel extends Panel
{
    TabPanel(chatClient1 app)
    {
        // Initialize the Components
        chatclient = app;	
        // Main Panel
        RightPanel = new CPanel(300, 500);

        Panel panel2 = new Panel();
        CardLayout cardlayout = new CardLayout();
        panel2.setLayout(cardlayout);
        UserPanel = new Panel();	  
        UserPanel.add("Center",new Label("User"));

        ImgScrollPanel = new Panel();
        ImgScrollPanel.setLayout(new BorderLayout());

        BuddyPanel = new Panel();
        BuddyPanel.setLayout(new BorderLayout());

        RoomPanel = new Panel();
        RoomPanel.setLayout(new BorderLayout());
	  
        panel2.add("UserPanel", UserPanel);
        panel2.add("RoomPanel", RoomPanel); 
        panel2.add("ImgScrollPanel", ImgScrollPanel); 
        panel2.add("BuddyPanel", BuddyPanel);

        cardlayout.show(panel2, "UserPanel");

        RightTab = new BorderPanel(this,chatclient, cardlayout, panel2, 210, 270);

        RightTab.addTab("USERS", "UserPanel");
        RightTab.addTab("ROOMS", "RoomPanel"); 
        RightTab.addTab("IMAGES", "ImgScrollPanel");
        RightTab.addTab("BUDDY", "BuddyPanel");
        RightPanel.add(RightTab);
        add(RightPanel);  
    }

    Panel LeftPanel, BuddyPanel, RoomPanel, ImgScrollPanel, UserPanel;
    CPanel RightPanel;
    BorderPanel RightTab;
    chatClient1 chatclient;
    public int i;
}

Finally,

If you want a TabPanel, you can import the TabPanel class in your applet or main application. Adding the code tab = new TabPanel(this); will embed it into your application.

Jeeva S

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jeeva S

Architect

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionneed help PinmemberAttaullah bablu6:53 30 Nov '11  
QuestionNeed your Assistance PinmemberNiraj Deshmukh12322:18 13 Nov '11  
GeneralCode java of Chat program Pinmemberthopt7:51 3 Nov '09  
GeneralNew in Java [modified] PinmemberaskPrins9:30 17 Jul '08  
GeneralHey! Pinmember138256ssn8:03 16 Sep '07  
There is no source code in your zip file.
GeneralRe: Hey! PinmemberaskPrins9:11 17 Jul '08  
General*-- How to GET the SOURCE CODE -- * Pinmembertheo2511:35 21 Feb '07  
Generalhave the coding Pinmembercoool_ajit19:44 17 Apr '06  
Generalplz send Pinmemberashishkumar.er5:59 20 Mar '06  
GeneralThere is an error in your run.bat file Pinsusscode rider19:30 17 Oct '04  
QuestionNo Source files!? PinmemberT.Haberkern0:39 19 Apr '02  
AnswerRe: No Source files!? Pinmembertedyoung10:36 2 Dec '03  
Answerhttp://www.codeproject.com/useritems/java_applet_chat_with_gui.asp PinmemberAltair_Liu18:47 12 Oct '04  
GeneralRe: http://www.codeproject.com/useritems/java_applet_chat_with_gui.asp Pinmemberksnare5:41 29 May '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 7 Jun 2010
Article Copyright 2002 by Jeeva S
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid