Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the component weight dynamically in 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.

like image 843
hungr Avatar asked Feb 07 '11 10:02

hungr


1 Answers

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)

like image 190
StanislavL Avatar answered Sep 20 '22 01:09

StanislavL