don't reset check box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aleplgr
    New Member
    • Aug 2007
    • 19

    #1

    don't reset check box

    Hi! this might be so easy but I can't make it work: I just have a check box, the user selects it, then the user exits that form, when the user comes back to the form I need the check box to be as the user left it.
    I defined the check box not initialized but if I select it, then leave that form and come back the check box appears unselected.
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Originally posted by aleplgr
    Hi! this might be so easy but I can't make it work: I just have a check box, the user selects it, then the user exits that form, when the user comes back to the form I need the check box to be as the user left it.
    I defined the check box not initialized but if I select it, then leave that form and come back the check box appears unselected.
    More information please. What GUI is this? Swing? AWT? SWT?

    Comment

    • aleplgr
      New Member
      • Aug 2007
      • 19

      #3
      Sorry, it's Swing...

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        Originally posted by aleplgr
        Sorry, it's Swing...
        I'm surprised then that the control doesn't maintain its state. Can you post a simple yet runnable example of this behaviour?

        edit: demo
        [CODE=Java]import java.awt.*;
        import java.awt.event. *;
        import javax.swing.*;

        public class CheckBoxExample {
        public static void main(String[] args) {
        EventQueue.invo keLater(new Runnable(){
        public void run() {
        createAndShowGU I();
        }
        });
        }

        static void createAndShowGU I() {
        final JFrame f = new JFrame();
        final JDialog d = new JDialog(f, "checkbox", false);
        d.getContentPan e().add(new JCheckBox("See if state is maintained"));
        d.pack();
        JButton btn = new JButton("show dialog");
        btn.addActionLi stener(new ActionListener( ){
        public void actionPerformed (ActionEvent e) {
        d.toFront();
        d.setVisible(tr ue);
        }
        });
        f.getContentPan e().add(btn);
        f.setDefaultClo seOperation(JFr ame.EXIT_ON_CLO SE);
        f.pack();
        f.setLocationRe lativeTo(null);
        d.setLocationRe lativeTo(f);
        f.setVisible(tr ue);
        }
        }[/CODE]
        If you close the dialog, then make it visible again you see that the checkbox state is maintained, so I don't see your problem.

        Comment

        Working...