简短的回答是,你不能,至少不能用那个版本的addTab
方法。Anything that gets added to a JTabbedPane
using that particular addTab
method will get all available screen space when its associated tab is selected.
在我看来,您想在同一个选项卡中放置多个Component
,或者更改该选项卡中组件的调整大小行为。JPanel
如果是这种情况,您应该首先使用该方法将您想要可视化的任何组件添加到 的实例中panel.add(Component component,Object constraints)
,然后将该面板添加到JTabbedPane
.
另一种选择是做这样的事情:
JTabbedPane tabs = ...
int index = ... //whatever index you're currently at
Object constraints = ...//these are your constraints
JPanel panel = ...//this is the panel you want constraints for
panel.setName("name"); //will be used as the title when added to tabs in next line
tabs.add(panel, constraints, index);
tabs.setToolTipTextAt(index, "this is a tooltip for 'panel'");
绝对不像单线那样吸引人,但仍然可以完成工作。