2
我想了解MigLayout,因此我想創建一個不同面板內的表。如何在MigLayout中的垂直單元內堆疊組件?
細胞2包含3個標籤,這應該疊加。因此,我試圖給電池2它自己的佈局center2.setLayout(new MigLayout("flowy"));
,但隨後其他部件得到雜亂:
那麼,有沒有一種方式,堆疊在小區2垂直的3個標籤?
[編輯]: center1和center2應該有相同的高度!
我的示例類PageThree.java:
public class PageThree extends JPanel{
public PageThree() {
setLayout(new MigLayout());
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new MigLayout("width 100%"));
JPanel topHeading = new JPanel();
JPanel westAreas = new JPanel();
JPanel center1 = new JPanel();
JPanel center2 = new JPanel();
// If I give center2 its own layout with flowy,
// the 3 labels are stacked vertically,
// but the other components get cluttered
// center2.setLayout(new MigLayout("flowy"));
JPanel center3 = new JPanel();
center1.add(new JLabel("center1"));
center2.add(new JLabel("center21"));
center2.add(new JLabel("center22"));
center2.add(new JLabel("center23"));
center3.add(new JLabel("center3"));
topHeading.add(new JLabel("topHeading1"));
topHeading.add(new JLabel("topHeading2"));
topHeading.add(new JLabel("topHeading3"));
westAreas.add(new JLabel("westAreas"));
contentPanel.add(center1, "width 40%");
contentPanel.add(center2, "width 60%, wrap");
contentPanel.add(center3, "width 50%");
contentPanel.add(topHeading, "width 100%, dock north, split 3");
contentPanel.add(westAreas, "dock west");
}
}