refresh JFrame after adding new Components

情到浓时终转凉″ 提交于 2019-11-29 10:59:01

问题


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.


回答1:


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




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/3718435/refresh-jframe-after-adding-new-components

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