本文介绍了在GridBagLayout中动态更改组件权重的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设现在JPanel中有一些组件,并且使用GridBagLayout安排了布局.是否可以动态更改组件的权重(权重或权重)(例如,按下按钮后)?谢谢.
Suppose now there are some components inside a JPanel and the layout is arranged using GridBagLayout. Is it possible to change the weight(weightx or weighty) of the components dynamically (e.g. after pressing a button)? Thank you.
推荐答案
使用新的GridBagConstraint删除并添加组件.通话结束后
Remove and add the component with a new GridBagConstraint. After that call
panel.revalidate();
panel.repaint();
使用该方法获取当前约束公共GridBagConstraints getConstraints(Component comp)
Use the method to get current constraints public GridBagConstraints getConstraints(Component comp)
这篇关于在GridBagLayout中动态更改组件权重的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!