This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTabs urgent!!!!!

 
Prashanth Bhanu
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prashanth Bhanu
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);

sectionTabPane.revalidate();
sectionTabPane.repaint();
}
});

while(itr.hasNext()){
Object ob = itr.next();
splitHashMap(ob,noOfSec.get(ob));//will return the arraylist for each section
}

return sectionTabPane;
}

private void splitHashMap(Object mainTabTitles,Object sectionWiseArrayList){
try{
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();
sectionTabPane.addTab(sectionWiseMainTabTitle,addChildTab(arrList));
}catch(Exception e){
e.printStackTrace();
}
}


private GUIBasePanel addChildTab(ArrayList sectionWiseArrayList) {
GUIBasePanel pnlBaseChild = new GUIBasePanel();
pnlBaseChild.setLayout(new BorderLayout());
try{
tab = new GUITabbedPane();
tab.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int i = tab.getSelectedIndex();
System.out.println("Change listener child ==>"+i);
tab.revalidate();
tab.repaint();
}
});
for(int g=0;g<sectionWiseArrayList.size();g++){
tab.addTab(sectionWiseArrayList.get(g).toString(),(JPanel)allPages.get(sectionWiseArrayList.get(g)));
}
pnlBaseChild.add(tab,BorderLayout.CENTER);
}catch (Exception e) {
e.printStackTrace();
}
return pnlBaseChild;
}
}

thanks in advance
 
Prashanth Bhanu
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well problem is resolved,when adding childtabs it should be assigned to tabs array.
regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic