Java+;Miglayout-上边距边界问题?

Java+;Miglayout-上边距边界问题?,java,swing,border,padding,miglayout,Java,Swing,Border,Padding,Miglayout,我对保证金有问题。也许这很容易解决,但我不知道原因是什么。我有四个组件,三个JScrollPanel和一个jpanel。组件的放置方式如下所示: 问题用红色椭圆标记。如何消除这一差距?我知道,这个问题与边界有关(即使我用相同的方法为每个组件创建边界)。我在用这个: setBorder(BorderFactory.createTitledBorder("Sterowanie:")); 但当我没有为JPanel(标签为“Sterowanie”的组件)设置边界时,它会填充所有的地方,没有边界。使用

我对保证金有问题。也许这很容易解决,但我不知道原因是什么。我有四个组件,三个JScrollPanel和一个jpanel。组件的放置方式如下所示:

问题用红色椭圆标记。如何消除这一差距?我知道,这个问题与边界有关(即使我用相同的方法为每个组件创建边界)。我在用这个:

setBorder(BorderFactory.createTitledBorder("Sterowanie:"));
但当我没有为JPanel(标签为“Sterowanie”的组件)设置边界时,它会填充所有的地方,没有边界。使用边界,它只填充边界区域。我用于放置组件的代码:

proxys = new ItemViewer("Numery:");
add(proxys, "height 65%, width 33%");

accs = new ItemViewer("Konta:");
add(accs, "height 65%, width 33%");

panel = new JPanel();
panelLayout = new MigLayout("insets 0 0 0 0");
panel.setBorder(BorderFactory.createTitledBorder("Sterowanie:"));
add(panel, "height 65%, width 34%, wrap");

log = new Log("Log:");
add(log, "height 35%, width 100%, span");

Hm?

不知道为什么会发生这种情况(我的第一个猜测是ItemView与普通面板的垂直默认对齐方式不同),但可以复制-并通过使所有细胞都可以生长来解决问题,无论是在细胞内还是在行内

    JComponent comp = new JScrollPane(new JTable(20, 1));
    comp.setBorder(new TitledBorder("Some Item"));
    JComponent other = new JScrollPane(new JTable(10, 1));
    other.setBorder(new TitledBorder("Other items"));
    JComponent panel = new JPanel();
    panel.setBorder(new TitledBorder("Stewhatever"));
    JTextArea log = new JTextArea();
    log.setBorder(new TitledBorder("Log"));

    MigLayout layout = new MigLayout("wrap 3, debug"); //, "", "[fill, grow]"); 
    JComponent content = new JPanel(layout);
    String cc = "width 33%, height 65%, grow";
    content.add(comp, cc);
    content.add(other, cc);
    content.add(panel, cc);
    content.add(log, "height 35%, span, grow");
在没有任何增长的情况下,代码片段将复制您的屏幕截图,并在cc或注释行约束中进行增长,所有上部组件都在顶部对齐


不确定这是一个bug还是应该预料到的

您使用miglaway的方式对我来说有点奇怪(请不要冒犯,我刚刚学会了另一种方式)。试试这个:

content.setLayout(new MigLayout("fill", "[sg, grow][sg, grow][sg, grow]", "[65%][35%]"));
content.add(topLeftComponent, "grow");
content.add(topMiddleComponent, "grow");
content.add(topRightComponent, "grow, wrap");
content.add(bottomComponent, "span 3, grow");

我知道它与“spirit”不同,但我总是发现这种风格更容易构建。

在使用
MigLayout
方面没有太多经验,虽然您尝试过使用,但您尝试过将其与
标题边框一起使用,只需添加一个
清空顺序
,希望这能在某种程度上有所帮助:-)当然没有冒犯:)我忘了将这个问题标记为已解决,我在一年前使用了kleopatra解决方案。但你的答案也很有用,也许有人会遇到同样的问题,然后他可以尝试两种解决方案。谢谢