Unselecting RadioButtons in Java Swing

前端 未结 10 1511
鱼传尺愫
鱼传尺愫 2021-01-01 09:06

When displaying a group of JRadioButtons, initially none of them is selected (unless you programmatically enforce that). I would like to be able to put buttons back into tha

10条回答
  •  不知归路
    2021-01-01 09:29

    I don't know if this will help but have you tried to use doClick() method?

    jRadioButtonYourObject.doClick();
    

    Input - NONE

    Return- void

    I had a similar problem and tried everything in this thread to no avail. So I took a look at all the methods of JRadioButton and found that method from JRadioButton's parent class.

    In my program, I had two radio button independent of each other and it was programed so that only one was selected.

    After the user enters data and hits a button the program clears all text fields and areas and deselects the radio button. The doClick() did the job of deselecting the radio button for me; the method "performs a "click"."

    I know yours is different and you probably would have to program the doClick() method for every radio button that is selected.

    http://docs.oracle.com/javase/7/docs/api/javax/swing/AbstractButton.html

    search for doClick()

提交回复
热议问题