后续问题 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 - JSplitPane + MiGLayout : how to enable proportional autoresizing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4852567/