以下情况:当我向面板添加JLabel时,我会得到不需要的填充/空间。我怎么能删除它?见左侧,我想要它像图像右侧那样。
这是我的简短测试代码,它产生的输出显示在上图的左侧:
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);
答案 0 :(得分:2)
之所以发生这种情况,是因为您向JPanel
添加标签,其中FlowLayout
使用默认的间隙。要解决此问题,您可以使用下一个:
JPanel line1 = new JPanel(new FlowLayout(FlowLayout.CENTER,0,0));
JPanel line2 = new JPanel(new BorderLayout());