How to remove JPanel padding in MigLayout?

泪湿孤枕 提交于 2019-12-13 15:46:29

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/25909104/how-to-remove-jpanel-padding-in-miglayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!