可能的重复项:
将按钮组件添加到 Java 中的 Java 选项卡式窗格
是否可以将按钮添加到 JTabbedPane 选项卡(选项卡本身),以便在单击时可以执行操作,例如关闭选项卡?
当然。首先添加一个选项卡,如下所示:
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.add( "title", content );
然后用这个更改"标题"标签:
tabbedPane.setTabComponentAt( 0, new JButton( "This is now a button!" ) );
// 0 is the tabindex