java GridBagLayout anchor

前端 未结 1 1273
独厮守ぢ
独厮守ぢ 2021-01-05 11:14

Learing GridBagLayout, The issue here is, the name label and combox don\'t show up on the top of the panel, but I have set its anchor to NORTH. Why ?

import          


        
相关标签:
1条回答
  • 2021-01-05 11:25

    You have to change

    gridBagConstraints.weighty = 0.0;
    

    to

    gridBagConstraints.weighty = 1.0;
    

    otherwise the area reserved for the component is slimmed to the size of the component, and it doesn't matter in which direction you "anchor" the component.

    The result after changing the weighty is the following:

    enter image description here

    0 讨论(0)
提交回复
热议问题