• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

CheckBox state

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Yeah, but is it art? What do you think tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic