0

How to reload a form in a JFrame? I have two forms, form1 and form2:

  1. form1 links to form2 using:

    new form2().show(); 
    this.setVisible(false);
    
  2. form2 links to form1 is success

  3. The problem is when form1 form2 links 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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
dtnder
  • 381
  • 2
  • 10
  • 25
  • 1
    1) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) 2) For better help sooner, post an [SSCCE](http://sscce.org/). 3) And please, stop talking Netbeans and start talking Java. – Andrew Thompson Nov 11 '12 at 11:23
  • 1
    Not been able to fully understand the term **"Reload a form in a JFrame" and I have two forms, form1 and form2**. I guess this [example](http://stackoverflow.com/a/13110320/1057230) might can help you, if I guessed, what you thinking in the right sense :-) – nIcE cOw Nov 11 '12 at 12:32
  • i mean how to close jframe without using setvisible. because jframe setVisible just hide it.Like a restart in pc, jframe exit and re-open again. – dtnder Nov 11 '12 at 13:24

1 Answers1

2

You can use CardLayout to 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, jframe exit and re-open again.

Although CardLayout is much more flexible, but you can always empty the Container, add the desired components and invoke validate()/repaint(), as shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • i mean how to close jframe without using setvisible. because jframe setVisible just hide it.Like a restart in pc, jframe exit and re-open again. – dtnder Nov 11 '12 at 13:20
  • @user1815938 : Again, I guess what you looking for is this [frameObject.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE)](http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation(int)) or `JFrame.DISPOSE_ON_CLOSE`, that might can serve as an alternative, to the context you are presenting. – nIcE cOw Nov 11 '12 at 13:50
  • @user1815938: I've elaborated above; also consider Gagandeep Bali's suggestion. – trashgod Nov 11 '12 at 15:04