2

Possible Duplicate:
Adding a button component to a java tabbed pane in java

Is it possible to add a button to a JTabbedPane tab (the tab itself) so that when clicked it could perform an action, for example close the tab?

Community
  • 1
  • 1
user1724416
  • 914
  • 2
  • 11
  • 24

1 Answers1

3

Sure. First add a tab like this:

JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.add( "title", content );

Then change the "title" label with this:

tabbedPane.setTabComponentAt( 0, new JButton( "This is now a button!" ) );
// 0 is the tabindex
icza
  • 389,944
  • 63
  • 907
  • 827
  • 2
    I don't think that this what the OP asked for. I think that it would like to have a close button like you have in Web-browsers. – Guillaume Polet Dec 17 '12 at 16:07
  • Not really what I was looking for, I want to button inside the tab, like in the browser when you click the cross. – user1724416 Dec 17 '12 at 16:38