Posts
60
Comments
36
Trackbacks
18
Java and Radio Buttons Using Netbeans 5.6 GUI Builder

To get through this tutorial, you must already be able to create a basic form with 3 or 4 radio buttons on it.  We are going to go over making and using these buttons in a functional example.  To start, I create a project selecting Java Application and then the Next button.  I rename my application to "RadioButtons", you may name it whatever you want to, I then deselect (uncheck) the "Create Main Class" option, followed by Finish. 

  1. Right Click on Source Packages and New -> Java Package, I name this radiobuttons.
    1-29-2009 5-16-59 PM
  2. Right Click radiobuttons (if you have named it the same as I have) -> New -> JFrame Form, which I name RadioButtons, and click finish.
    1-29-2009 5-21-34 PM
  3. From the Right hand side (maybe different for you), drag Button Group anywhere in your square panel and drop it (you won't see any changes here).
    1-29-2009 5-23-53 PM
  4. Now place your radio buttons, using the Radio Button (next to your Button Group).  I place four for this example.  I then shift-click (to select all of them).
    1-29-2009 5-35-02 PM
  5. Right click your selection -> Select Properties.  This step is where you group them together.  When you look at the properties, there is an option for button Grouping (seen below).  This will group them for our purposes here, select your buttonGroup (that was created in step 3).  Note: If you don't see a selection, you can go back to 3 now and carry out that step
    1-29-2009 5-37-13 PM
  6. At this stage, if you were to click "Play" or Run -> Main Project, you will see the radio buttons in a GUI that are grouped (allowing only 1 of the 4 to be selected at a time).
  7. Now, to put these radio buttons to use, we will add a button, with a click listener and a text area.  (Just drag and drop from the right hand group of objects).
    1-29-2009 5-47-22 PM
  8. To add the click listener to the button, Right Click the button, select Properties.  At the top of the pop up dialogue, select events -> scroll down to mouseClicked and select the ... on the right hand side.  This will take you to the picture below, where I named my event and selected Ok to close out dialogues.
    1-29-2009 5-53-13 PM
  9. This will take you into the code where you can create your code to do what you want it to do.  In this example, I am simply setting the text box to the value of the radio button that is selected.  And here is the corresponding code, below:
    1-29-2009 6-47-31 PM
  10. Press Play now.  :-)

There are a few things to note.  If you are using their text in a calculation, you will need to cast it properly.  There is most likely a better way to do this, but for beginner I believe this will get you started.  Feel free to comment, as always.

posted on Thursday, January 29, 2009 6:51 PM Print
Comments
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
shahid
5/14/2009 12:20 PM
  
this is best for radio button
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
Chris
9/15/2009 4:32 PM
  
Sweet. Helped a lot. Thanks!
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
Ankit Raghuvanshi
10/8/2009 1:18 PM
  
Hey this is really helpful.
Thank you.

Can u post the similar description for Jlist. I m unable to insert more than one rows from database table into Jlist
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
Russ Heaton
11/17/2009 7:56 PM
  
Excellent. Short and sweet. Prerequisites are stated in the first sentence, saving the reader (and writer) oodles of time.
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
Steve
12/23/2009 9:28 PM
  
I couldn't figure out how to use the Button Group until this short demonstration straightened everything out. Well done!
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
Sarfaraz khan
12/29/2009 11:31 PM
  
thanks this is really help ful
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
ganesh
2/15/2010 8:06 AM
  
thank u its working....
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
Yasas
2/22/2010 12:51 PM
  
I'm 100% beginner, but this make me much better in Radiobuttons.

Thank you so much !!
Keep it up !!

Can I get more help from u ??
I need to get few more things
JTable , JCombobox

Thank you !
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
Registry Cleaner Reviews
3/2/2010 6:02 AM
  
Thanks for this post. Good ideas come to us all at some point and it seems you've got yours here.
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
RegCure Review
3/2/2010 6:03 AM
  
Thanks for this post. I really like using NetBeans but don't know about how effective it would be at creating one of these tools.
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
jancel
3/2/2010 8:17 AM
  
NetBeans seems to be the best answer for me. I use Mac and Windows and this has been the friendliest between the two. I haven't given eclipse much thought, but I should probably look into that more.
Gravatar
# wdqzfnlu
wdqzfnlu
3/29/2010 9:59 AM
  
wdqzfnlu
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
Sumudu Ayya
5/2/2010 9:51 AM
  
This is most useful. Thanks
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
Dante
6/4/2010 4:47 PM
  
Nice dude, but what about the casting for data types?
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
Jeff Ancel
6/4/2010 5:19 PM
  
I will do that in later post. @Dante
Gravatar
# re: Java and Radio Buttons Using Netbeans 5.6 GUI Builder
Sheikh
7/22/2010 8:11 PM
  
It is really helpful for Beginners.Thanks

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 4 and 3 and type the answer here:
News
My Developer Notebook! This also happens to be my opinion place. Thanks for coming by.