Question

Well I am quite new to MigLayout and have read about it on whitepaper and Quickstart but that was not enough.I put a panel and below that I want one panel to occupy 30% of window and other the rest of it i.e, 70%. When window is resized(maximised) the components are messing up. The code is as follows:

    Mig_tmp1(){
    j=new JFrame("test");
    j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    j.setLayout(new MigLayout("debug,fill","[70px]5[:70:250,grow]","[:100:]10[fill,grow]"));

    one=new JPanel();
    one.setBackground(Color.red);
    two=new JPanel();
    two.setBackground(Color.ORANGE);
    three=new JPanel();
    three.setBackground(Color.BLUE);

    j.add(one,"wrap,span,grow");
    j.add(two,"grow");//,"w 40!");
    j.add(three,"grow");

    //j.pack();
    j.setSize(400, 600);
   j.setVisible(true); 
}
Was it helpful?

Solution

You can specify the percentage that the component should grow in the constructor using grow XX where XX is the percentage to grow.

In your example:

j.setLayout(new MigLayout("debug,fill", "[grow 70, fill]5[grow 30, fill]", "[:100:]10[fill,grow]"));

That's assuming you want the orange panel to take 70% of the screen and the blue panel 30% of the screen at all times.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top