質問

I've two jRadioButtons in Java application. Let's say Male and Female. Initially one is selected. While selecting another, the previous should be unselected and vice-versa. How to make it work? Also how can it be used to store in database?

役に立ちましたか?

解決

You can give same name to all the radio buttons, from which you want to select only one. That way, you will be able to select just one button out of all. This you can do by creating a ButtonGroup.

Now, if you want to add the selected item to the database, just get the value corresponding to the name of Button Group, you will get the value of selected button.

See documentation and tutorial

他のヒント

What you need to use is a ButtonGroup component. Have a look at: How to Use the ButtonGroup Component

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top