• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTabs urgent!!!!!

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well problem is resolved,when adding childtabs it should be assigned to tabs array.
regards
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic