简体   繁体   English

MigLayout-选择性成分填充

[英]MigLayout - selective component fill

I am trying to add a JTabbedPane to a panel, with buttons above it for controls. 我正在尝试将JTabbedPane添加到面板,其上方具有用于控件的按钮。 I am using MigLayout. 我正在使用MigLayout。

But, I cannot get the JTabbedPane to fill without the buttons also filling when they don't need to. 但是,我无法让JTabbedPane填充,而在不需要按钮时也无法填充按钮。

Take the following SSCCE: 采取以下SSCCE:

public static void main(String[] args) {
    JPanel panel = new JPanel(new MigLayout(new LC().fill()));
    panel.add(new JButton("+"));
    panel.add(new JButton("-"), "wrap");
    panel.add(new JTabbedPane(), "span, grow");
    JFrame frame = new JFrame();
    frame.add(panel);
    frame.setSize(new Dimension(300, 500));
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

This produces a panel that looks like this: 这将产生一个如下所示的面板:

在此处输入图片说明

But, if I remove fill() from the layout constraints ( JPanel panel = new JPanel(new MigLayout(new LC())); ), it looks like this: 但是,如果我从布局约束中删除fill()JPanel panel = new JPanel(new MigLayout(new LC())); ),则如下所示:

在此处输入图片说明

How do I make the JTabbedPane to fill the content area while the JButton s do not fill? 我如何使JTabbedPane填充内容区域,而JButton不填充?

If you don't want a constraint be applied to all cells, don't tell the Layout ;-) Instead, use column and row constraints: three columns and let only the last fill and grow and two rows with the last growing 如果您不希望将约束应用于所有单元格,请不要告诉Layout ;-)相反,请使用列和行约束:三列,只允许最后填充和增长,两行最后增长

JPanel panel = new JPanel(new MigLayout("", "[][][fill, grow]", "[][fill, grow]"));
panel.add(new JButton("+"));
panel.add(new JButton("-"), "wrap");
panel.add(new JTabbedPane(), "span, grow");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM