Starting GridBagLayout from top left corner in Java Swing

后端 未结 6 739
执念已碎
执念已碎 2021-02-13 18:39

I\'m new to Java Swing and I have been struggling to start the GridBagLayout from top left corner so that c.gridx=0 c.gridy=0 will put my object on the top left corner.

6条回答
  •  眼角桃花
    2021-02-13 18:49

    Read the section from the Swing tutorial on How to Use GridBagLayout. The secton on "weightx,weighty" states:

    Unless you specify at least one non-zero value for weightx or weighty, all the components clump together in the center of their container.

提交回复
热议问题