Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: setEnabled causing checkbox to deselect

  1. #1
    Junior Member
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default setEnabled causing checkbox to deselect

    Greetings. I am working on an ap;et for my company and have come to a little snag. I have a stateChanged listener for a radioButton. the radioButton is part of a buttonGroup and when this specific radioButton is selected, it should enable a checkbox on my form. Conversely when the radioButton is deselected, the checkbox should disable but NOT deslect if it is selected.

    the problem is that the checkbox is always being deselected when the radioButton is deselected. Here is the code that I am working with.

    private void radioB3StateChanged(javax.swing.event.ChangeEvent evt) {
            // TODO add your handling code here:
            if (radioB3.isSelected() == true) {
                checkbox1.setEnabled(true);
            } else {
                checkbox1.setSelected(false);
                checkbox1.setEnabled(false);
            }
        }

    radioB3 is 1 of 3 radio buttons in a group. this code works fine by itself. This next snippet seems to be the cause of my trouble.

    private void checkbox0StateChanged(javax.swing.event.ChangeEvent evt) {
            // TODO add your handling code here:
            if (upgradeData.isSelected() == true) {
                tabContainer.setEnabledAt(2, true);
                radioB1.setEnabled(true);
                radioB2.setEnabled(true);
                radioB3.setEnabled(true);
                checkbox2.setEnabled(true);
            } else {
                tabContainer.setEnabledAt(2, false);
                radioB1.setEnabled(false);
                radioB2.setEnabled(false);
                radioB3.setEnabled(false);
                checkbox1.setEnabled(false);
                checkbox2.setEnabled(false);
            }
        }

    checkbox0 is a checkbox that should enable/disable the group of radioButton(3) and 2 checkboxes. I do not want it to deselct anything, only disable them. It is however deslecting the checkbox1 and disabling it.

    Am I doing something wrong here or am I not understanding what setEnabled(false) really does? Any assistance would be very appreciated.
    --
    DewBoy3d
    Rochester, NY


  2. #2
    Junior Member
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: setEnabled causing checkbox to deselect (SOLVED)

    Well it appears that I was premature in my posting. After recompiling (no changes related to this) it is working as intended. Not sure what happened there.
    --
    DewBoy3d
    Rochester, NY

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: setEnabled causing checkbox to deselect

    Hello dewboy3d, welcome to the Java Programming Forums

    I'm glad your issue sorted itself out on its own! Those are the best kind of problems lol
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    Junior Member
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: setEnabled causing checkbox to deselect

    Thank you for the welcome JavaPF. I've only been at Java now for about a month. I began learning it solely for this project. I don't believe I have a solid foundation and am currently using an IDE as a crutch. Eventually I'd like to get away from that and begin to truly understand what is happening behind the scenes. The powers that be requested a quick solution for this project and as such I wasn't given much time.

    All-in-all I am becoming happier with Java but still have some nagging issues with the language. The inability to switch on a string value, for one. The second being, reloading an applet that has been updated without closing the browser. I know the trick about pressing 'x' in the console window but my users aren't able to view the console based on policy restrictions on their pc. Aside from those 2 issues, I think my progress is going well.

    If you have any advice, please feel free to share it regardless of how trivial. I'm always eager to try new things. Oh, for the record, I am using NetBeans as my IDE and am developing for Java 1.5 (I really wish they would update that at work). Thanks again
    --
    DewBoy3d
    Rochester, NY