为什么我的组件不包装在Swing的FlowLayout中?

为什么我的组件不使用FlowLayout包装在这个JPanel中? 它们只是在屏幕上运行,只是部分可见。

JPanel panel = new JPanel(new FlowLayout()); panel.add(new JLabel("TEST")); // ... repeat adding JLabels until they go off screen when they SHOULD wrap // to the next line... 

这是我的全部代码(除了添加和打包框架)。 我误解了FlowLayout吗? 我是否必须在标签或面板上设置某种尺寸?

那是因为FlowLayout没有。 我知道,这很糟糕。

但是,你可以看看WrapLayout ,这是解决这个问题的方法