JSplitPane + MiGLayout: how to enable autoresizing

笑着哭i 提交于 2019-12-11 03:11:20

问题


I'm doing something wrong here: I want to have two JButtons in a JSplitPane in a JPanel in a a JFrame, where the buttons fill the JSplitPane.

Here's what I get when I resize the JFrame:

The buttons stay their normal size, and the JSplitPane doesn't allow adjusting.something

How do I fix this?

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);
    }
}

回答1:


Add the "push" and "grow" contraints to your split pane, like this:

panel.add(splitpane, "push, grow");


来源:https://stackoverflow.com/questions/4833383/jsplitpane-miglayout-how-to-enable-autoresizing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!