JSplitPane + MiGLayout: how to enable automation

I'm doing something wrong here: I want to have two JButtons in a JSplitPane in a JPanel in a JFrame, where the buttons fill the JSplitPane.

Here is what I get when I resize a JFrame:

enter image description here

The buttons keep their normal size, and JSplitPane does not allow you to change .something

How to fix it?

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, ""); splitpane.setTopComponent(new JButton("top")); splitpane.setBottomComponent(new JButton("bottom")); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } 
+2
source share
1 answer

Add "yours" and "grow" in your break area, for example:

 panel.add(splitpane, "push, grow"); 
+2
source

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


All Articles