wood burning stoves 2.0*
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTabs urgent!!!!!" Watch "JTabs urgent!!!!!" New topic
Author

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="http://taubler.com/articles/" 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);

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

Joined: Sep 25, 2003
Posts: 110
Well problem is resolved,when adding childtabs it should be assigned to tabs array.
regards
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JTabs urgent!!!!!