0

如何添加 jpanel 并在 jtabbedpane 选项卡中传递一些约束。

addTab("name",null,here to pass panel but can't pass constraints, "tooltip");

更详细的...

在选项卡中添加 jpanel 时,面板中的内容会延伸到整个框架,所以我决定将框架设置为 GridBagLayout,但是添加选项卡时通常必须将面板作为参数之一传递,不允许任何约束!我的问题是如何在选项卡中添加面板时添加约束以准确告诉框架放置面板的位置。

4

1 回答 1

0

简短的回答是,你不能,至少不能用那个版本的addTab方法。Anything that gets added to a JTabbedPaneusing that particular addTabmethod 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'");

绝对不像单线那样吸引人,但仍然可以完成工作。

于 2013-10-22T16:18:16.823 回答