开发者

Change the component weight dynamically in GridBagLayout

开发者 https://www.devze.com 2023-02-09 04:18 出处:网络
Suppose now there are some components inside a JPanel a开发者_如何学编程nd the layout is arranged using GridBagLayout. Is it possible to change the weight(weightx or weighty)of the components dynamica

Suppose now there are some components inside a JPanel a开发者_如何学编程nd 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.


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消