Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

refresh JFrame after adding new Components

Tags:

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.

like image 514
reox Avatar asked Sep 15 '10 14:09

reox


People also ask

How do you refresh Java?

The java. util. ServiceLoader. reload() method clears this loader's provider cache so that all providers will be reloaded.

What is revalidate Java?

revalidate(): This method tells the layout manager to recalculate the layout that is necessary when adding components.


2 Answers

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

like image 179
crusam Avatar answered Oct 18 '22 16:10

crusam


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.

like image 27
dogbane Avatar answered Oct 18 '22 18:10

dogbane