문제

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