Java Swing (BoxLayout) alignment issues

后端 未结 2 438
夕颜
夕颜 2021-01-22 11:33

I am extremely new to Java Swing, and I\'m having quite a bit of issues getting a nice layout going. I have checked out google, and even other answers on this website, but no in

2条回答
  •  庸人自扰
    2021-01-22 12:19

    Read the section from the Swing tutorial on How to Use BoxLayout for the basics of using a BoxLayout as well as a section on alignment issues.

    Basically you need to make sure the alignmentX value of all components is set to be left aligned.

    Also:

    1. Don't use setPreferredSize() to set the size of a component. Each Swing component will determine its own preferred size.
    2. Use Java naming conventions. Variable names should NOT start with an upper case character.

提交回复
热议问题