views:

225

answers:

1

I am trying to create a layout that will looking like:

+---+--------+---+
|   |        |   |
|   |        |   |
+---+        +---+
|   |        |   |
|   |        |   |
+---+--------+---+

Central cell should be twice as wide as other. I am trying achieve this with such code:

    val panel = new JPanel(new MigLayout("debug", "grow","grow" ))
    panel.add(new JPanel)
    panel.add(new JPanel, "span 2 2")
    panel.add(new JPanel, "wrap")
    panel.add(new JPanel)
    panel.add(new JPanel)

But as result all my cells have same width:

+----+----+----+
|    |    |    |
|    |    |    |
+----+    +----+
|    |    |    |
|    |    |    |
+----+----+----+

What I do wrong? I am using Scala but I don't think that problem is herein.

UPDATE Maybe someone can explain why this didn't work. Even if i try reproduce example from QuickStart guide it didn't work :

alt text

My code:

    val panel = new JPanel(new MigLayout("debug", "grow","grow" ))
    wrapTab.add(new JPanel)
    wrapTab.add(new JPanel, "span 2 2")
    wrapTab.add(new JPanel, "wrap")
    wrapTab.add(new JPanel)
    wrapTab.add(new JPanel, "wrap")
    wrapTab.add(new JPanel)
    wrapTab.add(new JPanel)

And as result all cols has equal size.

+10  A: 
val panel = new JPanel(new MigLayout("debug", 
              "[grow 25][grow 50][grow 25]","grow" ))
panel.add(new JPanel)
panel.add(new JPanel, "spany 2")
panel.add(new JPanel, "wrap")
panel.add(new JPanel)
panel.add(new JPanel)
Ken Bloom
Can you explain please. And why my method didn't work? I am using QuickStart guide and my case is very similar for one of the examples.
masterzim
@masterzim: I'm guessing that when you finished inserting things, the `MigLayout` looked to see what had been inserted and decided that there were really only 3 columns of stuff, so it decided to weight those 3 columns equally. (I could be wrong about that logic. I've never used the `MigLayout` before, and rarely ever write GUI programs -- I just looked at the whole quick start guide, and decided to try a different strategy than yours. But I did test my solution, so I know it works.)
Ken Bloom