we have one dialog box, in that dialog, there is one Check Box, Ok and Cancel buttons. suppose user selected checkbox and click ok button, when user opens again that dialog box, the check box should be as selected.
can anyone give idea, how to implment this.
i know we can do this by using setSelected(true) and setSelected(false) methods.
Well, there could several ways to do that. One option could be not to dispose the dialog box, but to hide it. That way, next time you show it, the stated it had when it was hidden is still available. This could be a simple way, but it will not save the state after the application has been close.
If you need to dispose the dialog box, then you could save the state of the checkbox elsewhere, in another object, and then recover it when you create dialog box again.
Finally, if you need to save the state even after the application has been closed, then you will need to write this information to disk and recover it the next time the dialog box is painted.
Easiest way to display a Dialog is use the appropriate JOptionPane.showXXX method. These methods, among other parameters, accept "Object message". Construct a JPanel, put your check box and other stuff you require inside that panel, and use the panel as the message Object. If you keep on referencing the same panel instance, the check box state will be always retained.