Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple equal tabs in jTabbedPane

 
Liwuen Chew
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings everyone! I hope someone can help me with this doubt!

I have a jTabbedPane with one tab and several components in it (example: one label and one button). I have a button outside of the jTabbedPane which makes a new tab appear in the jTabbedPane (additional to the existing one)
Is there a way to make the new tab to contain a label and a button like the previous tab? I mean to keep adding tabs to the jTabbedPane and make all this tabs to contain a label and a button?

Thanks!
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can add any child only once to any parent. However, you can create multiple instances of the child component and add them.

In pseudo code
1) Subclass JPanel
2) Add whatever components required to this panel
3) While creating a new tab, create and use a new instance of this subclassed panel.
 
Liwuen Chew
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey! That works!
Thanks!
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are Welcome!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic