Question

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.

Was it helpful?

Solution

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)

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top