我在列中有一些控件,我希望看起来像这样,并且有一行是例外:
+----+------------------+----+--------------------+
| X1 | Y1 | X5 | Y5 |
+----+------------------+----+--------------------+
| X2 | Y2 | X6 | Y6 |
+----+------------------+----+--------------------+
| X3 | Y3 | X7 | Y7 |
+----+-----+------------+----+--------------------+
| Special1 | Special 2 with long description |
+----+-----+------------+----+--------------------+
| X4 | Y4 | X8 | Y8 |
+----+------------------+----+--------------------+
我想知道如何使用MigLayout。我正在使用Swing JavaBuilders及其精简的YAML语法:
X1 Y1 X5 Y5
X2 Y2 X6 Y6
X3 Y3 X7 Y7
Special1 Special2
X4 Y4 X8 Y8
我基本上想做的是将一行(Special1 / Special2)作为例外,但我不知道该怎么做(上面的YAML片段不正确)。
答案 0 :(得分:2)
这应该这样做:
public static void main(String[] args)
{
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(400, 250));
Container cp = frame.getContentPane();
cp.setLayout(new MigLayout("fill, debug"));
String wrap = "wrap,";
String span2 = "spanx 2,";
String span3 = "spanx 3,";
cp.add(new JLabel("X1"));
cp.add(new JLabel("Y1"), span2);
cp.add(new JLabel("X5"));
cp.add(new JLabel("Y5"), wrap);
cp.add(new JLabel("X2"));
cp.add(new JLabel("Y2"), span2);
cp.add(new JLabel("X6"));
cp.add(new JLabel("Y6"), wrap);
cp.add(new JLabel("X3"));
cp.add(new JLabel("Y3"), span2);
cp.add(new JLabel("X7"));
cp.add(new JLabel("Y7"), wrap);
cp.add(new JLabel("Special 1"), span2);
cp.add(new JLabel("Special 2 with long description"), span3 + wrap);
cp.add(new JLabel("X4"));
cp.add(new JLabel("Y4"), span2);
cp.add(new JLabel("X7"));
cp.add(new JLabel("Y8"));
frame.pack();
frame.setVisible(true);
}
享受。