我在这里做错了:我想在 JFrame 中的 JPanel 中的 JSplitPane 中有两个 JButton,其中按钮填充 JSplitPane。
这是我在调整 JFrame 大小时得到的结果:
按钮保持正常大小,JSplitPane 不允许调整。
我该如何解决?
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);
}
}