I have 2 forms in Netbeans, 1 form will launch and the user will input information. Then if the user wants to, will open up the other jframe. The jframe that the user was working on will close. Now from the newly opened jframe, the user decides to go back to the previous frame. The problem is when the user does decide to go back to the previous frame, the text in the textboxes are gone, the buttons that were enabled are disabled, and the combobox selection resets. Does anyone know how I can save the state of all these elements? Thank you.
Asked
Active
Viewed 325 times
2 Answers
0
An application should generally only have a single JFrame.
You can probably use a Card Layout to swap different panels. Read the Swing tutorial on How to Use CardLayout for more information and example.
Other options or to use a JTappedPane or JInternalFrames. The tutorial also has section on these components.

camickr
- 321,443
- 19
- 166
- 288
0
Would something like this help?
public class MyFrame extends JFrame{
private JCheckBox box1;
public MyFrame(){
box1 = new JCheckBox();
}
public void work(){
if(getbox().isSelected){
//work
}else{
//do else
}
}
public JCheckBox getbox1(){
return this.box1;
}
public JCheckBox setSelectedbox1(boolean set){
getbox1().setSelected(set);
}
If you want to keep that object alive you can use:
myFrame.setVisible(false)
myFrame.setVisible(true)

Petro
- 3,484
- 3
- 32
- 59
-
How can I save the text in textboxes, so when the jframe reloads, the text can still be there? – Navio53 Jul 01 '13 at 03:32
-
store it in a String when a user clicks a button like save: String info = textBox.getText(); However if you just use .setVisible(true/false), it will remain because the jframe will not actually 'close'. Hope that helps. – Petro Jul 03 '13 at 16:15