How to add a radio button group in a core java program such that only one radio button is selected at one time?

前端 未结 3 1965
旧时难觅i
旧时难觅i 2020-12-17 10:32

I am building a project in core java. BUt i\'m stuck in making a radio button group ( for entering the gender (male/female). For that i need a radio group such that only one

3条回答
  •  失恋的感觉
    2020-12-17 11:27

    Here's a radio button grouping:

    JRadioButton button1 = ...;
    button1.setSelected(true);
    JRadioButton button2 = ...;
    ButtonGroup group = new ButtonGroup();
    group.add(button1);
    group.add(button2);
    

提交回复
热议问题