java – JSplitPane MiGLayout:如何启用比例自动调整
作者:互联网
后续问题to my other one;
如何启用比例调整大小?我认为这会起作用,但它没有:
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);
}
}
我想要的是,当我调整整个帧的大小时,顶部/底部按钮大小的比例是恒定的. (默认比例为1:2)
我怎样才能做到这一点?
解决方法:
splitPane.setResizeWeight(0.333);
标签:java,swing,miglayout,jsplitpane 来源: https://codeday.me/bug/20190610/1211758.html