Save State of Buttons (Whether Enabled Or Disabled), Textboxes, and JComboBox Selections in Netbeans Java?

StackOverflow https://stackoverflow.com/questions/17387332

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.

Était-ce utile?

La 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)

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top