How to use JRadioButtons

Start a new project or add a new JFrame to existing project.Then in the swing palette window drag and drop the radio buttons in to frame.

and also you have to add a buttongroup component in to frame.Radio buttons you can see in the frame but buttongroup you cannot see in the frame. We use button group because without button group you cannot select one option at a one time.

Now select all the radio buttons and Right click–>Properties –>ButtonGroup –>select ButtonGroup1.Now compile and run it.Then see it works nicely.Now drag and drop a new label and rename it as lblresult.When i am selection radio button appropriate text should be displayed in the label.

Just Right click on the radio button and goto event—>Action performed event and type below code in the method body

lblDisplay.setText("You have selected Forth Radio Button");
// method .setText() use to set some text on the textbox or label or something.

Download Netbeans example from here

3 thoughts on “How to use JRadioButtons

  1. Yes, It’s really a good work to share the knowldge amoung the friends. Don’t forget to mention the names of the original writer if somhow you had to to opt out something from somewhere.
    Also it’s perfect if you’re learning PHP as well, then you will be one of the perfect blend. Keep on good work but be little concern on you mobile bill, as I saw in many of your images the NOKIA PC Suite being connected to the internet and left idle.

  2. It was difficult to set button group to radio button in eclipse. In this way i was able to add button group to radio button in eclipse,thank you very much…….

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.