网格布局的负值表示什么
我遇到了这段代码,其中网格约束具有负行和列值。它意味着什么?
GridBagConstraints cons = new GridBagConstraints();
cons.gridx = 0;
cons.gridy = -2;
cons.gridwidth = 0;
cons.gridheight = 1;
cons.anchor = 10;
cons.fill = 0;
I came accross this code where Grid constraints are having negative row and column values. What does it signify?
GridBagConstraints cons = new GridBagConstraints();
cons.gridx = 0;
cons.gridy = -2;
cons.gridwidth = 0;
cons.gridheight = 1;
cons.anchor = 10;
cons.fill = 0;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
gridx
和gridy
的负值表示相对定位,即组件放置在之前添加的组件的右侧(对于gridx
)或就在组件下方(对于gridy
)。您不应直接使用负值,而应使用 GridBagConstraints.RELATIVE 来代替。
Negative values for
gridx
andgridy
indicate relative positioning, i.e. the component is placed just to the right of the component added before (forgridx
) or just below the component (forgridy
).You should not use negative values directly but
GridBagConstraints.RELATIVE
instead.