Centering a JLabel on a JPanel

后端 未结 5 871
花落未央
花落未央 2020-11-22 14:32

I\'m using the NetBeans GUI builder to handle my layout (I\'m terrible with LayoutManagers) and am trying to place a simple JLabel so that it is always centered (horizontall

5条回答
  •  一整个雨季
    2020-11-22 15:04

    There's many ways to do this, depending on the layout manager(s) you use. I suggest you read the Laying Out Components Within a Container tutorial.

    I believe the following will work, regardless of layout manager:

    JLabel.setHorizontalAlignment(SwingConstants.CENTER)

提交回复
热议问题