由于某种原因,布局似乎不想在 JTabbedPane 中工作。它没有流到下一条“线”上,而是就像它有无限的水平空间一样:(但是在没有 JTabbedPane 的情况下直接将所有内容添加到框架中效果很好......
在我的框架中:
JTabbedPane tabs = new JTabbedPane(JTabbedPane.TOP);
this.getContentPane().add(this.tabbedPane);
JPanel tab = new TestTab();
tabs.add("Test", tab)
还有我的 TestTab 构造函数(扩展 JPanel)
contentBox = new Box(BoxLayout.Y_AXIS);
JPanel groupPanel = new JPanel();
groupPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
groupPanel.setBorder(BorderFactory.createTitledBorder("Group"));
//add some paired items to it. The intention is each of these "sub groups"
//should stay together,with the sub groups themselves being liad out left to
//right, top to bottom
for(int i=0; i<10; ++i)
{
String label = "Button " + i;
Box itemBox = new Box(BoxLayout.X_AXIS);
JButton buttonA = new JButton(label + " A");
JButton buttonB = new JButton(label + " B");
itemBox.add(buttonA);
itemBox.add(buttonB);
groupPanel.add(itemBox);
}
contentBox.add(groupPanel);
//will be more content stuff to be added vertically below,
//suppose will have same issue
this.add(contentBox);