Solved

Clearing a selection in a Checkboxgroup

Posted on 2001-06-28
3
268 Views
Last Modified: 2006-11-17
I have a checkboxgroup, myGroup with individual boxes male, female.

I want a "clear" function to reset the choice to null. Nothing works. setState(false) does not work for me on myGroup or male, female.

How can I do that?
0
Comment
Question by:HanRui
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Expert Comment

by:eattrig
ID: 6236174
Try this out, this should be compilable:


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class Test
{
    CheckboxGroup myGroup = new CheckboxGroup();

    public Test()
    {
        Checkbox male = new Checkbox("Male", myGroup, false);
        Checkbox female = new Checkbox("Female", myGroup, false);

        male.setFont(new Font("Dialog", 1, 14));
        male.setLocation(20, 10);
        male.setSize(80, 30);

        female.setFont(new Font("Dialog", 1, 14));
        female.setLocation(20, 40);
        female.setSize(80, 30);

        JButton button = new JButton("Deselect All");
        button.setLocation(10, 80);
        button.setSize(100, 45);
        button.setBorder(new BevelBorder(BevelBorder.RAISED));
        button.addActionListener
        (
            new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    // this is where you set the selected
                    // checkbox to null, or none
                    myGroup.setSelectedCheckbox(null);
                }
            }
        );

        JFrame frame = new JFrame();
        frame.setLocation(300, 300);
        frame.setSize(120, 155);
        frame.setResizable(false);
        frame.getContentPane().setLayout(null);
        frame.getContentPane().add(male);
        frame.getContentPane().add(female);
        frame.getContentPane().add(button);
        frame.setVisible(true);
    }
    public static void main(String[] args)
    {
        new Test();
    }
}

Hope this helps.
0
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 6236426
Add a 'hidden' checkbox (ie. not visible) to your group and set that checkbox. This will clear the state of the other two.
0
 
LVL 92

Expert Comment

by:objects
ID: 6236436
Thanks for the points :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle SQL syntax check  without executing 6 109
how to install java on RHEL image on EC2 4 58
hibernate example using maven 12 82
printf performancy 11 86
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question