带约束的java传递面板
如何添加jpanel并在jtabbedpane选项卡中传递一些约束
addTab("name",null,here to pass panel but can't pass constraints, "tooltip");
更多详细说明
在选项卡中添加jpanel时,面板中的内容会延伸到整个框架,因此我决定将框架设置为GridBagLayout,但在添加选项卡时,通常必须将面板作为参数之一传递,不允许任何约束!我的问题是,在选项卡中添加面板时,如何添加约束,以准确告知框架放置面板的位置
# 1 楼答案
简单的回答是,您不能,至少不能使用
addTab
方法的那个版本。使用特定的addTab
方法添加到JTabbedPane
的任何内容都将在选中其关联的选项卡时获得所有可用的屏幕空间在我看来,您似乎想将多个
Component
放在同一个选项卡中,或者更改该选项卡中某个组件的大小调整行为。如果是这种情况,您应该首先使用panel.add(Component component,Object constraints)
方法将任何要可视化的组件添加到JPanel
的实例中,然后将该面板添加到JTabbedPane
另一种选择是这样做:
当然没有一艘客轮那么吸引人,但仍然完成了任务