如何在MigLayout中删除JPanel填充?

时间:2014-09-18 09:34:34

标签: java swing miglayout

以下情况:当我向面板添加JLabel时,我会得到不需要的填充/空间。我怎么能删除它?见左侧,我想要它像图像右侧那样。

enter image description here

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

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

1 个答案:

答案 0 :(得分:2)

之所以发生这种情况,是因为您向JPanel添加标签,其中FlowLayout使用默认的间隙。要解决此问题,您可以使用下一个:

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

enter image description here