nhouser9
nhouser9

Reputation: 6780

MigLayout wrap two lines

I just started using MigLayout.

I have read some documentation, including the quick start guide for MigLayout, as well as searched some SO questions, but I didn't find an answer. I'm sure it's something obvious, but like I said, this is my first time with this layout manager.

I am trying to make one of the rows in my MigLayout twice as tall as the others.

My code started out as:

public GameWindow() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new MigLayout("fill"));
    add(new PanelHud(), "grow, span 2, wrap");
    add(new PanelWorldView(), "grow");
    add(new PanelDetailView(), "grow, wrap");
    add(new PanelMenu(), "grow, span 2");
    pack();
    setVisible(true);
}

which produces:

enter image description here

That's a good start, but what I want is for the middle row to be two times as tall as the top and bottom rows. At first I thought I could just make the middle elements span two rows, but that didn't work:

public GameWindow() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new MigLayout("fill"));
    add(new PanelHud(), "grow, span 2, wrap");
    add(new PanelWorldView(), "grow, span 1 2");
    add(new PanelDetailView(), "grow, span 1 2, wrap");
    add(new PanelMenu(), "grow, span 2");
    pack();
    setVisible(true);
}

enter image description here

It looks like the middle row is indeed the correct size, but the bottom row was displaced. How can I fix this?

Upvotes: 0

Views: 556

Answers (1)

tuempl
tuempl

Reputation: 109

3 possible solutions (I probably went a bit over board).

use auto wrap so miglayout detects full rows itself:

setLayout(new MigLayout("fill, wrap 2"));
add(new PanelHud(), "grow, span 2");
add(new PanelWorldView(), "grow, span 1 2");
add(new PanelDetailView(), "grow, span 1 2");
add(new PanelMenu(), "grow, span 2");

base you layout on cells:

setLayout(new MigLayout("fill", "[][]", "[][][][]"));
add(new PanelHud(), "grow, cell 0 0 2 1");
add(new PanelWorldView(), "grow, cell 0 1 1 2");
add(new PanelDetailView(), "grow, cell 1 1 1 2");
add(new PanelMenu(), "grow, cell 0 3 2 1");

use grow weight (although this does not seem to keep the 2:1 ratio for small windows sizes):

setLayout(new MigLayout("fill", "[][]", "[grow 100][grow 200][grow 100]"));
add(new PanelHud(), "grow, span 2, wrap");
add(new PanelWorldView(), "grow");
add(new PanelDetailView(), "grow, wrap");
add(new PanelMenu(), "grow, span 2");

Upvotes: 2

Related Questions