JSplitPane + MiGLayout: how to enable proportional auto-implementation

The next question is for my other ;

How to enable proportional resizing? I thought this would work, but it is not:

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); } } 

I would like the aspect ratio of the top / bottom buttons to be constant when I resize the entire frame. (default ratio is 1: 2)

How can i do this?

+4
source share
2 answers
 splitPane.setResizeWeight(0.333); 
+6
source

I cannot speak for MigLayout, which I do not know. However, in my opinion, the best solution to this problem is swing-generic: you add a ComponentListener to your JSpiltPane and resize the component it contains by a factor built with respect to size.

+2
source

Source: https://habr.com/ru/post/1337795/


All Articles