Centering a JLabel in a JPanel

后端 未结 6 2211
情歌与酒
情歌与酒 2020-12-05 14:26

I have a panel derived from JPanel. I have a custom control derived from JLabel. I am attempting to center this custom JLabel on my pa

6条回答
  •  -上瘾入骨i
    2020-12-05 14:57

    BoxLayout is the way to go. If you set up a X_AXIS BoxLayout, try adding horizontal glues before and after the component:

    panel.add(Box.createHorizontalGlue());
    panel.add(label);
    panel.add(Box.createHorizontalGlue());
    

提交回复
热议问题