JSplitPane + MiGLayout:如何启用自动调整大小 [英] JSplitPane + MiGLayout: how to enable autoresizing

查看:289
本文介绍了JSplitPane + MiGLayout:如何启用自动调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里做错了:我想在JFrame的JPanel中的JSplitPane中有两个JButton,其中的按钮会填充JSplitPane.

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.

这是我调整JFrame大小时得到的:

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

按钮保持其正常大小,并且JSplitPane不允许进行调整.

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

我该如何解决?

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

推荐答案

将推送"和增长"约束添加到拆分窗格中,如下所示:

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

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

这篇关于JSplitPane + MiGLayout:如何启用自动调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆