开发者

refresh JFrame after adding new Components

开发者 https://www.devze.com 2023-01-16 10:48 出处:网络
I want to add some new Components to开发者_运维技巧 my JFrame during runtime when a button is pressed.

I want to add some new Components to开发者_运维技巧 my JFrame during runtime when a button is pressed. This works so far, but i have to resize the window manually to see the new components.

Is there any Action I can fire or a method to call to refresh the window? Any help appreciated. Thanks in advance.


You have to revalidate(); the frame. If that doesn't work you also have to call repaint();


Call

revalidate();
repaint();

revalidate tells the layout manager to reset based on the new component list. This will also trigger a call to repaint.

repaint is used to tell a component to repaint itself.


in java repaint(); working for me. while revalidate(); not working for me.

0

精彩评论

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