Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MigLayout usage

A question for those familiar with MigLayout

sorry couldn't think of a more appropriate name for the question...

I'm trying to create a layout that will end up looking like the following:

+---------+---------+
|  btn1   |  btn2   |
+---------+---------+
|                   |
|       btn3        |
|                   |
+-------------------+

when the window is resized the components btn1 and btn2 should fill the x-axis (half each), and the component btn3 should fill both the x-axis and all of the available space in the y-axis.

how would you achieve this?

here's some code to start with:

public static void main(String[] args)
{
    JFrame window = new JFrame();
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container cp = window.getContentPane();

    cp.setLayout(new MigLayout(""));
    cp.add(new JButton("btn1"), "");
    cp.add(new JButton("btn2"), "");
    cp.add(new JButton("btn3"), "");

    window.pack();
    window.setVisible(true);
}
like image 211
pstanton Avatar asked Jan 12 '10 23:01

pstanton


2 Answers

This is pretty easy in MigLayout:

setLayout(new MigLayout("fill"));

add(new JButton("button 1"), "w 50%");
add(new JButton("button 2"), "w 50%, wrap");
add(new JButton("button 3"), "grow, push, span");

If you read pstanton's original question, I think the layout instructions required are very close to how he formulated it. That's what I like about MigLayout :)

like image 137
Alexander Malfait Avatar answered Nov 11 '22 05:11

Alexander Malfait


I've never used miglayout, but it should be something like the following:

...
cp.add(new JButton("btn1"));
cp.add(new JButton("btn2"), "wrap");
cp.add(new JButton("btn3"), "span");
...
like image 32
Alex Ntousias Avatar answered Nov 11 '22 04:11

Alex Ntousias