2012-08-10 64 views
0

爲什麼我的組件使用FlowLayout封裝在這個JPanel中?他們只是跑出屏幕,只是部分可見。爲什麼我的組件不能在Swing的FlowLayout中包裝?

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?我是否必須在標籤或面板上設置某種尺寸?

+1

我猜的解決方案是,它是與'panel'的父容器。 – 2012-08-10 21:01:18

回答

6

這是因爲FlowLayout沒有。我知道,它很糟糕。

但是,你可以看看WrapLayout這是這個問題

+1

[here rest](http://stackoverflow.com/questions/8196530/java-vertical-flowlayout-with-horizo​​ntal-scrolling)+1 – mKorbel 2012-08-10 21:47:58

+1

@mKorbel不錯:D – MadProgrammer 2012-08-10 21:54:27

+0

糟透了。我已經開始使用MigLayout,這太棒了。 – sdasdadas 2012-08-28 02:59:40

相關問題