• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CheckBox state

 
deepa sabbani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11165
14
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic