Change the component weight dynamically in GridBagLayout

一个人想着一个人 提交于 2020-06-24 13:42:07

问题


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.


回答1:


Remove and add the component with a new GridBagConstraint. After that call

panel.revalidate();
panel.repaint();

Use the method to get current constraints public GridBagConstraints getConstraints(Component comp)



来源:https://stackoverflow.com/questions/4920209/change-the-component-weight-dynamically-in-gridbaglayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!