9

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.

Glorfindel
  • 19,729
  • 13
  • 67
  • 91

1 Answers1

11
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
  • 52,354
  • 11
  • 101
  • 164
  • 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. –  Jun 29 '10 at 21:12
  • 5
    @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 Jun 30 '10 at 00:37
  • 1
    For the record: Columns are not necessarily of equal width, the two spanned columns were given half the width of the other columns because they had half the contents. The original attempt would have worked in a layout where there were rows above/below the spanning component. – Jacob Raihle Aug 24 '12 at 11:51