This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding button to a tabbed pane  RSS feed

 
Melki Joe
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kindly give me a solution in how to add a jbutton to a jtabbed pane. I am having a tabbed pane which contains three tabs and in the fourth place i need to add an button. How can we do it as we see in eclipse? Kindly give me the solution.

Thank you.
 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Melki Joe:
Kindly give me the solution.

Not A Code Mill. We do not just give full solutions.

First read How to Use Tabbed Panes.
 
Melki Joe
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh! sorry actually the thing is I want to know, is there a way to add button to the tabbed pane. In tabbed pane we usually add panels which will display as tabs. I want to add a button in the place where the the tab icon is displayed. I hope you might have undestood my query.

thank you.
 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's why I added that second link. There is an exact example on how to do it.
 
Melki Joe
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry again, I dont need the button in the headder of the tab. I need such button next to the tab headder but in the same row.

Thank you.
 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I didn't get that.

You're not going to like the effort you will need to put into this, but I think you need to create your own instance of javax.swing.plaf.TabbedPaneUI. Perhaps you can override javax.swing.plaf.basic.BasicTabbedPaneUI, but it is still going to be quite some work.


An easier alternative is add an empty tab with just a button on it. If this tab is activated switch back to the previous tab (use a change listener for this). This will show the button in a tab though, so it's not that nice looking.
 
Yves Zoundi
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As said by Rob, you'll need to play with the TabbedPaneUI if you want to add extra components to the tabbedpane.

Please kindly think about that proposed solution Melki
 
Melki Joe
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you both are right I think rob have now got my requirement. I will try your suggetion. But still I am eager to know is there any other easy way to do this, like drawing a rectangle and making it as button.

Thank you.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!