Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSplitPane + MiGLayout: how to enable proportional autoresizing

A followup question to my other one;

How do I enable proportional resizing? I thought this would work but it doesn't:

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import net.miginfocom.swing.MigLayout;

public class SplitPaneQuestion {
    public static void main(String[] args) {
        JFrame frame = new JFrame("SplitPaneQuestion");
        JPanel panel = new JPanel();
        frame.setContentPane(panel);
        panel.setLayout(new MigLayout("","[]","[grow]"));
        JSplitPane splitpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        panel.add(splitpane, "push, grow");

        splitpane.setTopComponent(new JButton("top"));
        splitpane.setBottomComponent(new JButton("bottom"));
        splitpane.setDividerLocation(0.333);

        frame.pack();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

What I would like is for the ratio of the top/bottom button sizes to be constant when I resize the entire frame. (with a 1:2 ratio by default)

How can I do this?

like image 709
Jason S Avatar asked Feb 26 '23 05:02

Jason S


1 Answers

splitPane.setResizeWeight(0.333);
like image 66
camickr Avatar answered Apr 28 '23 06:04

camickr