如何在 MigLayout 中删除 JPanel 填充? [英] How to remove JPanel padding in MigLayout?

查看:37
本文介绍了如何在 MigLayout 中删除 JPanel 填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下情况:当我向面板添加 JLabel 时,我得到了不需要的填充/空间.我怎样才能删除它?见左侧,我希望它像图片显示的右侧一样.

Following situation: when I add a JLabel to a panel, i get unwanted padding/space. How can i remove it? See left side, i want it like the right side of the image shows.

这是我的简短测试代码,它产生上图左侧所示的输出:

here's my short test-code, that produces the output shown on the left side of the image above:

setLayout(new MigLayout("gapy 0, debug"));
JPanel line1 = new JPanel();
JPanel line2 = new JPanel();;
line1.add(new JLabel("Text 1"));
line2.add(new JLabel("Text 2"));
add(line1, "wrap, align left");
add(line2);

推荐答案

发生这种情况是因为您将标签添加到 JPanel 中,该标签使用 FlowLayout 并将间隙作为默认设置.要解决此问题,您可以在接下来使用:

That happens because you add labels to JPanel which used FlowLayout with gaps as default. To fix that you can use next:

    JPanel line1 = new JPanel(new FlowLayout(FlowLayout.CENTER,0,0));
    JPanel line2 = new JPanel(new BorderLayout());

这篇关于如何在 MigLayout 中删除 JPanel 填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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