[英]Change the component weight dynamically in GridBagLayout
Suppose now there are some components inside a JPanel and the layout is arranged using GridBagLayout. 假设现在JPanel中有一些组件,并且使用GridBagLayout安排了布局。 Is it possible to change the weight(weightx or weighty) of the components dynamically (eg after pressing a button)?
是否可以动态更改组件的权重(权重或权重)(例如,按下按钮后)? Thank you.
谢谢。
Remove and add the component with a new GridBagConstraint. 删除并使用新的GridBagConstraint添加该组件。 After that call
那个电话之后
panel.revalidate();
panel.repaint();
Use the method to get current constraints public GridBagConstraints getConstraints(Component comp) 使用该方法获取当前约束公共GridBagConstraints getConstraints(Component comp)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.