Frage

I'm trying to lay out components and want to set the width in a specific way. From what i understand, miglayout sets width like "width min:pref:max". So in my case i want the following:

layout explained

My problem is with comp2. It stops growing after about 200px and I can't figure out why, since I don't specify a maximum width.

I also checked the miglayout swing demo but they don't have my exact case there. They have one with unlimited width, but not minimum width specified.

To make sure the panel expands, I set the background of the panel to gray, and I can see that it expands without any problem.

Please tell me if anything needs to be clarified and I'll gladly try to explain better.

EDIT: Here is a SSCCE

import java.awt.Color;
import javax.swing.*;
import net.miginfocom.swing.MigLayout;

public class SSCCE {
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        JPanel panel = new JPanel(new MigLayout(
                "",
                "[grow, fill]",
                ""));
        panel.setBackground(Color.LIGHT_GRAY);

        JButton comp1 = new JButton("Comp1");
        JButton comp2 = new JButton("Comp2");
        JButton comp3 = new JButton("Comp3");

        panel.add(comp1, "width 50:150:150, growx");
        panel.add(comp2, "growx");
        panel.add(comp3, "width 50:70:70, growx");      

        frame.add(panel);
        frame.pack();
        frame.setVisible(true);     
    }
}

I does grow, but i want it to take all the space available, and it does not. Can it have something to do with the settings on the panel?

EDIT 2: With this code:

panel.add(comp1, "width 50:150:150");
panel.add(comp2, "width 10:n:n");
panel.add(comp3, "width 50:70:70, right");  

I get this:

enter image description here

But i want the middle component to occupy all available space.

War es hilfreich?

Lösung

Feeling free :-)

Here's a snippet that gives all extra space to the middle column.

JPanel panel = new JPanel(new MigLayout(
        "debug",
        "[][grow, fill][]",
        ""));
JButton comp1 = new JButton("Comp1");
JButton comp2 = new JButton("Comp2");
JButton comp3 = new JButton("Comp3");

panel.add(comp1, "width 50:150:150");
panel.add(comp2); 
panel.add(comp3, "width 50:70:70");      
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top