Results 1 to 6 of 6
  1. #1
    javaguy345 is offline Member
    Join Date
    May 2011
    Posts
    15
    Rep Power
    0

    Default Radio button validation

    Hey I searched the forum and the net and can't seem to find any information on how I make it so if the user doesn't select a radio button it will display a message.

    if (?????) //I just dont know what to put here
    {
    JOptionPane.showMessageDialog(null, "Please select a button")
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default

    Is it a group of buttons, and one has to be selected?
    ie a ButtonGroup?
    Then see which button is selected...it'll return null if nothing is.

  3. #3
    javaguy345 is offline Member
    Join Date
    May 2011
    Posts
    15
    Rep Power
    0

    Default

    I tried it like

    if(bgrp1.getSelection() = null)

    but it wouldn't work

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default

    And what does "it wouldn't work" mean?

  5. #5
    javaguy345 is offline Member
    Join Date
    May 2011
    Posts
    15
    Rep Power
    0

    Default

    it says:
    unexpected type
    required: variable
    found: value

    So I think I have to use a variable instead of null or do it a different way, but I don't know what variable I would put there just an int with a value of 0? I'll try it and get back to you.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default

    Ah.
    Looking at the bit you gave a couple of posts ago...
    It's ==, not =.

Similar Threads

  1. Radio Button
    By S-NESH in forum New To Java
    Replies: 6
    Last Post: 02-04-2011, 05:03 PM
  2. Customized Radio Button
    By Javified in forum AWT / Swing
    Replies: 6
    Last Post: 12-13-2010, 07:06 AM
  3. Clear Radio Button
    By Reborn in forum New To Java
    Replies: 6
    Last Post: 07-25-2010, 05:21 PM
  4. Radio Button help!
    By javanator in forum New To Java
    Replies: 3
    Last Post: 04-25-2010, 08:01 PM
  5. How to use SWT Radio Button
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 02:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •