java - Save Checkbox state in a Panel/Dialog -
I am new to swings and I have a doubt:
I have a dialog box, There is a dialog, a check box, OK and Cancel button. Assume that the user selects the checkbox and click on the OK button, when the user re-opens that dialog box, the check box should be selected.
Anyone can give ideas, how it can be applied.
I know that I can do this using set-selected (true) and I can set selected (false) ways.
But how the status of the check box can be saved.
You will JOptionPane and they will be displayed properly.
For example, if you make
JCheckBox and send it after the code to
JOptionPane is closed, you can check the status of the check box And can store it anywhere. The next time you want to display the dialog before passing the check box, set your position previously stored. For example (for display purposes only):
last JFrame f = new JFrame ("checkbox test"); F.setDefaultCloseOperation (JFrame.DO_NOTHING_ON_CLOSE); F.addWindowListener (New WindowAdapter () {// I store the checkbox status in a boolean variable here: Boolean save; @ Override public wide window closing {// now user wants to close the application}, ask confirmation : // We create a check box with the initial value of the stored position: jck box cb = new jesickbox ("Save settings before saving", save); int riz = joppenpen.Show Conf (Dialog) (empty, new object [] {"Are you sure you want to get out?", Cb}, "exit?", Joppenpan.ocaankla_option); // dialog is closed, you check the check box Can be saved = cb.is selected (); if (res == JOptionPane.OK_OPTION) {if (save) {// settings can be saved here.} // and exit (only by settling the frame) f. Dispose ();}}}); F.getContentPane () Add (New JLabel ("Try Closing Application")); F.pack (); F.setLocationRelativeTo (zero); F.setVisible (true);
Comments
Post a Comment