将面板添加到BorderLayout区域,元素未按其应包装

时间:2013-05-30 01:31:51

标签: java swing applet flowlayout

所以我在init()内有一些类似于applet的代码:

layout = new BorderLayout();
setLayout(layout);

northPanel = new JPanel(new FlowLayout());

northPanel.add(inputDropDown);
northPanel.add(lowBoundLabel);
northPanel.add(lowBoundField);
northPanel.add(highBoundLabel);
northPanel.add(highBoundField);
northPanel.add(new JLabel("using"));
northPanel.add(categoriesField);
northPanel.add(new JLabel("categories"));
northPanel.add(showTotalsBox);
northPanel.add(refreshButton);

add(northPanel, BorderLayout.NORTH);

现在,当我测试它时,所有元素都是直线,当没有足够的空间时不要环绕。我甚至确保指定面板是FlowLayout(即使它是默认值)并且它没有改变任何东西。

它们不应该换行而不是仅仅离开屏幕吗?这是怎么回事?我将northPanel更改为BorderLayout,将这些元素拆分为单独的面板并将其添加到NorthSouth,从而提出了一个临时解决方案。然而,这些元素在屏幕上消失,没有必要的空间,所以我宁愿让它们环绕。

1 个答案:

答案 0 :(得分:2)

这实际上就是FlowLayout的工作方式,烦人的不是......

请看一下WrapLayout而不是......

相关问题