Daniel Paczuski Bak
Daniel Paczuski Bak

Reputation: 4080

MigLayout Panel inside a MigLayout panel - aligning it to the bottom

enter image description here

The panel to the right with all the buttons, I would like to align to the bottom.

JPanel easternDock = new JPanel(new MigLayout("", ""));
easternDock.add(button1, "wrap");
....
this.add(easternDock);

I'm thinking I could add a component above all the buttons and make it grow in the y dimension to fill the screen, but I'm not sure what component I'd use for that and I can't find any components designed to do such a thing.

Upvotes: 0

Views: 1211

Answers (1)

Matt Hubbard
Matt Hubbard

Reputation: 101

The way I would do it is to have another panel within the "easternDock" panel which contains all the components and have "easternDock" push this other panel to the bottom using the push Column/Row constraint.

From the MiG Cheat sheet : http://www.miglayout.com/cheatsheet.html

":push" (or "push" if used with the default gap size) can be added to the gap size to make that gap greedy and try to take as much space as possible without making the layout bigger than the container.

Here is an example:

public class AlignToBottom {

public static void main(String[] args) {
    JFrame frame = new JFrame();

    // Settings for the Frame
    frame.setSize(400, 400);
    frame.setLayout(new MigLayout(""));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Parent panel which contains the panel to be docked east
    JPanel parentPanel = new JPanel(new MigLayout("", "[grow]", "[grow]"));

    // This is the panel which is docked east, it contains the panel (bottomPanel) with all the components
    // debug outlines the component (blue) , the cell (red) and the components within it (blue)
    JPanel easternDock = new JPanel(new MigLayout("debug, insets 0", "", "push[]")); 

    // Panel that contains all the components
    JPanel bottomPanel = new JPanel(new MigLayout());


    bottomPanel.add(new JButton("Button 1"), "wrap");
    bottomPanel.add(new JButton("Button 2"), "wrap");
    bottomPanel.add(new JButton("Button 3"), "wrap");

    easternDock.add(bottomPanel, "");

    parentPanel.add(easternDock, "east");

    frame.add(parentPanel, "push, grow");
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

}

}       

Upvotes: 3

Related Questions