In Java can anyone explain grouping for radio buttons or check boxes and how to add components to a group? Solution We are creating a radiobutton as shown as below JRadioButton male1 = new JRadioButton(\"Male\"); JRadioButton fmale1 = new JRadioButton(\"FeMale\"); Male and FeMale are the name of the radiobutton we can group a radiobutton together by using this header file \"javax.swing.ButtonGroup \" as shown below ButtonGroup group = new ButtonGroup(); group.add(male1); group.add(fmale1); follow these steps while using a ButtonGroup component. Subclass JFrame Call ContextPane together with a layout manager Declare and configure a set of radio buttons Instantiate a ButtonGroup object Call the add method on that buttongroup object in order to add each button to the group .