This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTabs urgent!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTabs urgent!!!!!" Watch "JTabs urgent!!!!!" New topic

JTabs urgent!!!!!

Prashanth Bhanu
Ranch Hand

Joined: Sep 25, 2003
Posts: 110
Hi friends,

I've to randomly generate tabs(JTabbedPane).Is a two level tabs.For example Party as one tab and Details as the other tab.Now under party.I've tabs customer,investor and benificiary.Under Details i've customerDetails and investor details.
Now the thing is when the main tab say Pary is selected it should be in red color and details should be Green in color.
Under Party,Customer tab should have the color of the panel attached to it,say white.Where as investor and benificiary should have the color of party tab(i.e red).
Similarly when the Details tab is selected.Party tab should become green and details should be red and under the details tab customer details again have the color of the panel under it (white).And Investor details will be red.

Looks tricky and please give some idea if possible with some code samples.
Thanks in advance...
dave taubler
Ranch Hand

Joined: May 15, 2001
Posts: 132
I'd say there are two directions you could go.

1. The simplest is probably to attach a ChangeListener to your main (top-level) JTabbedPane, and listen for the different tabs to be selected. Then use JTabbedPane.setBackgroundAt(int index, Color background) to alter the color of the various tabs as needed.
2. Create your own instance of TabbedPaneUI for each of the JTabbedPanes, and set them via setUI(). This can be tricky and time consuming, though, if you're not familiar with this approach already.

Dave Taubler<br />Specializing in <a href="" target="_blank" rel="nofollow">Java and Web Development</a>
Prashanth Bhanu
Ranch Hand

Joined: Sep 25, 2003
Posts: 110
Thanks for that reply.I'm using the change listner
I've added tab inside the other tab.When i print the index of the tab selected i'm getting the correct index when clicked on the main tab.But for the child tabs i get the corrct tab index when ever i click on the last main tab and its children.Whre as for all the other tabs i'm getting index as zero......where am i going wrong?

public GUITabbedPane createTabedPane(HashMap noOfSec,HashMap Pages){
System.out.println("noOfSec "+noOfSec+" Pages"+Pages);
allPages = Pages;
Set set = noOfSec.keySet();
Iterator itr = set.iterator();
sectionTabPane = new GUITabbedPane();
sectionTabPane.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int i = sectionTabPane.getSelectedIndex();
System.out.println("Change listener ==>"+i);


Object ob =;
splitHashMap(ob,noOfSec.get(ob));//will return the arraylist for each section

return sectionTabPane;

private void splitHashMap(Object mainTabTitles,Object sectionWiseArrayList){
arrList = new ArrayList();
arrList = (ArrayList)sectionWiseArrayList;
String sectionWiseMainTabTitle = mainTabTitles.toString();
//now using this arraylist,allpages
System.out.println("arrList.length "+arrList.size());
GUIPanel p = new GUIPanel();
}catch(Exception e){

private GUIBasePanel addChildTab(ArrayList sectionWiseArrayList) {
GUIBasePanel pnlBaseChild = new GUIBasePanel();
pnlBaseChild.setLayout(new BorderLayout());
tab = new GUITabbedPane();
tab.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int i = tab.getSelectedIndex();
System.out.println("Change listener child ==>"+i);
for(int g=0;g<sectionWiseArrayList.size();g++){
}catch (Exception e) {
return pnlBaseChild;

thanks in advance
Prashanth Bhanu
Ranch Hand

Joined: Sep 25, 2003
Posts: 110
Well problem is resolved,when adding childtabs it should be assigned to tabs array.
wood burning stoves
subject: JTabs urgent!!!!!
Similar Threads
Transparent color for the panel !
changing text color on selected JTabbedPane tab
HTML tab slider issues
Help with TabbedPanel and panel in struts 2