Search code examples
javaswinguser-interfacefluid-layout

Make dynamic layout Java Swing


How can I achieve this effect using Swing: enter image description here

When resizing of the width the JFrame, I want the blue JPanel to be fluid and the green JPanel to be fixed. When resizing the height, I want both to be fixed. I also want the blue JPanel to not have less than some predefined width and the green JPanel to never move under the blue JPanel, remaining always on the right.


Solution

  • The MigLayout was designed for these situations: http://www.miglayout.com/

    JPanel panel = new JPanel();
    panel.setLayout(new MigLayout(
        "", 
        "[grow][200px]", // Column constraints
        "[100px]"        // Row constraints
    ));