aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes CheckBox state Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "CheckBox state" Watch "CheckBox state" New topic
Author

CheckBox state

deepa sabbani
Greenhorn

Joined: Apr 11, 2008
Posts: 8
i am new to swings. i have one doubt

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.

but how to save the state of the check box.
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
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.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10372
    
    8

Originally posted by deepa sabbani:

but how to save the state of the check box.


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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
 
subject: CheckBox state