How to reload a form in a JFrame? I have two forms, form1 and form2:
-
form1links toform2using:new form2().show(); this.setVisible(false); -
form2links toform1is success -
The problem is when
form1form2links to existing data are not shown.
I want to ask is there any other way than setVisible() method because it seems just to hide it.
You can use
CardLayoutto switch between forms. This example navigates with buttons; this example navigates with a combo. You can make navigation conditional based on what filled on your form.Addendum: Like a restart in pc,
jframeexit and re-open again.Although
CardLayoutis much more flexible, but you can always empty theContainer, add the desired components and invokevalidate()/repaint(), as shown here.