2

我在这里做错了:我想在 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);
    }
}
4

1 回答 1

2

将“push”和“grow”约束添加到拆分窗格中,如下所示:

panel.add(splitpane, "push, grow");
于 2011-01-29T00:16:12.593 回答