gpt4 book ai didi

java - JSplitPane + MiGLayout : how to enable proportional autoresizing

转载 作者:搜寻专家 更新时间:2023-11-01 01:47:37 26 4
gpt4 key购买 nike

后续问题 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com