Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Enable and Disable Tab in Java

                         

In this section you will learn how to enable and disable any tab in a TabbedPane component of Java Swing. The tabbed pane container can have one or more tables. All the tabs have a specific area in same place. Whenever you will click on any tab, the components added to the tab will be displayed. Sometimes it is necessary to disable some of the tabs. Following figure shows a frame in which some tabs are disabled:

Swing JTabbedPane component with some enabled and disabled tabs

This program shows the multiple tabs on the frame. These  tabs have a suitable name and index number. To enable or disable any tab you can use the setEnabledAt(int index, Boolean value) function. Tabs are by default enabled. Following are some methods and APIs that you can use in your program to enable or disable the tabs.

addTab():
This is the method of JTabbedPane class, adds the tabs to the panel or other other container component. The parameter description of the function are as follows:

  • First is the title of the tab of string data type
  • Second is the icon for the tab
  • Third is the component which is displayed on the corresponding tab
  • And last is the tool tip text for the tab

setEnabledAt(int index, Boolean value):
This is the method of JTabbedPane class, enables or disables the tab. This method takes two argument in which, first is the index number of the tab which has to be enabled or disabled and another argument is the boolean value. If the boolean value is TRUE then tab get enabled other wise tab gets disabled.

Here is the code of program:

import javax.swing.*;

public class EnableAndDisableTab{
  public static void main(String[] args) {
    EnableAndDisableTab t = new EnableAndDisableTab();
  }

  public EnableAndDisableTab(){
    JFrame frame = new JFrame("Enabling and Disabling a Tab in a JTabbedPane Container");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    JPanel panel1 = new JPanel();
    JPanel panel2 = new JPanel();
    JPanel panel3 = new JPanel();
    JPanel panel4 = new JPanel();
    JTabbedPane tpane = new JTabbedPane();
    tpane.addTab("Index", null, panel, "This is enable.");
    tpane.addTab("Table of contents", null, panel1, "This is disable.");
    tpane.addTab("Types of colors", null, panel2, "This is enable.");
    tpane.addTab("Types of computers", null, panel3, "This is disable.");
    tpane.addTab("Category", null, panel4, "This is enable.");
    tpane.setEnabledAt(1false);
    tpane.setEnabledAt(3,false);
    frame.add(tpane);
    frame.setSize(400,400);
    frame.setVisible(true);
  }
}

Download this example

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

tabs are numbered just like arrays (they start at 0 NOT 1). so im guessing that you only have one tab because you technically tried to disable the 2nd tab by saying (1,false) and the error says that you are out of bounds. therefore solution should be:

tpane.setEnabledAt(0,false);

Posted by sean j on Thursday, 07.12.07 @ 03:05am | #21114

Hi,

I'm interested in disable some of tabs of my TabbedPane. I have built my interface with netbeans 5.5 and I've tried to use tpane.setEnabledAt(1,false) in Post-Creation Code, but I received an error like:
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 >= 0"

What can I do?



Posted by Gorka Esnal on Wednesday, 05.2.07 @ 19:53pm | #15177

Latest Searches:
editable dropdown
select a row of data t
emailing file using js
tab controls in jsp
array sum
java random numbers
create protected folde
permutation combinati
display day in html
Copy One Database Tabl
notes on javax.sql.*
SUBMITTING MULTIPLE FO
remember
tree component web jav
multipage
BPEL Tutorials
Checkbox
b tree implementatio
RegistrationServlet.ja
getinit
request.setAttribute i
jsp trim char
download tomcat
Parsix GNU/Linux 0.76
download sample jsf ap
Combattons la programm
change color in JTabl
Flex TreeGrid
insert query in HQL
what is interface in j
JSP in error page
filereader
html:img
javamail spring
getting integer input
builb.xml
swt sample program
do while in java
Javascript Menus Image
cookie
program in java to dra
prime numbers between
changehashtablevalue
url redirecting in ser
clear values from a fo
finding the square of
apachi
tabbed pane
String value to array
Get first day of week?
getaddress()
SOA for the real world
upsasting
resultsetmethods
rich:pickList
covert uppercase to lo
session.get
FORMAT YEARS
methode overriding in
session.set
how to get applicate s
entryset
working of paint funct
send file
?бâ?????бâ????
logic iterate
count the number of di
JSF Data tree
draw existing image
string variable
DatabaseOracleOracleSQ
Reports
JFrame.extendedState
file input output
displaytag
jsp login by insertin
java jtable
???аÐ??????аÐ?????а
tag libraries
Photoshop Textures and
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.