Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设现在 JPanel 中有一些组件,并且布局是使用 GridBagLayout 排列的。是否可以动态更改组件的重量(weightx 或 weighty)(例如按下按钮后)?谢谢你。
使用新的 GridBagConstraint 移除并添加组件。在那次通话之后
panel.revalidate(); panel.repaint();
使用获取当前约束的方法 public GridBagConstraints getConstraints(Component comp)