在JTabbedPane选项卡中添加JButton

时间:2012-12-17 15:07:28

标签: java swing jtabbedpane

  

可能重复:
  Adding a button component to a java tabbed pane in java

是否可以向JTabbedPane选项卡(选项卡本身)添加一个按钮,以便在单击时可以执行操作,例如关闭选项卡?

1 个答案:

答案 0 :(得分:3)

不确定。首先添加一个这样的标签:

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

然后用以下内容更改“标题”标签:

tabbedPane.setTabComponentAt( 0, new JButton( "This is now a button!" ) );
// 0 is the tabindex