0

I have some controls in columns that I would like to look like this, and there is one row that is an exception:

+----+------------------+----+--------------------+
| X1 | Y1               | X5 | Y5                 |
+----+------------------+----+--------------------+
| X2 | Y2               | X6 | Y6                 |
+----+------------------+----+--------------------+
| X3 | Y3               | X7 | Y7                 |
+----+-----+------------+----+--------------------+
| Special1 |  Special 2 with long description     |
+----+-----+------------+----+--------------------+
| X4 | Y4               | X8 | Y8                 |
+----+------------------+----+--------------------+

and I was wondering how to do it with MigLayout. I am using Swing JavaBuilders with its condensed YAML syntax:

X1        Y1               X5    Y5
X2        Y2               X6    Y6
X3        Y3               X7    Y7
Special1     Special2
X4        Y4               X8    Y8

What I basically would like to do is make one row (the Special1/Special2) an exception, but I'm not sure how to do it (the above YAML fragment is not right).

pstanton
  • 35,033
  • 24
  • 126
  • 168
Jason S
  • 184,598
  • 164
  • 608
  • 970

1 Answers1

2

this should do it:

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);
}

enjoy.

pstanton
  • 35,033
  • 24
  • 126
  • 168
  • ah, sorry .. didn't understand (know about) SwingBuilders/YAML. I'll leave my answer here since it might help you conceptualise your solution but obviously it doesn't solve your problem... – pstanton Dec 22 '10 at 07:36
  • +1 for a nonJavabuilders example (not that I will use it, but it gets me thinking about things). What does "debug" do? – Jason S Dec 22 '10 at 13:19
  • shows the layout borders so you can see what's going on. http://migcalendar.com/miglayout/cheatsheet.html – pstanton Dec 22 '10 at 20:54