DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: JRadioButtons and JOptionPane

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Location
    Chicago
    Posts
    108

    Exclamation JRadioButtons and JOptionPane

    Hello everyone, I haven't been on this forum in quite a while, and well I need a little help. I have to display a dialog box where the user has to choose one of two options that are possible. I am using a JOptionPane with two JRadioButtons in a ButtonGroup. I am succesful in displaying the dialog and everything, but I can't figure out a way to get the values of the radio buttons after the user chooses the options and presses ok.

    Thanks in advance

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Have you coded and implemented an ActionListener? Take a look at the following Java tutorial page:

    http://java.sun.com/docs/books/tutor...ts/button.html

  3. #3
    Join Date
    Oct 2004
    Location
    Chicago
    Posts
    108
    First of all Im sorry for posting this question, I should have done some more googling before posting this. For anyone who might need this in the future here is how I ended up solving my problem.

    Code:
    static JRadioButton getSelected(ButtonGroup group)
    	{
    		for(Enumeration e= group.getElements(); e.hasMoreElements();){
    				JRadioButton b = (JRadioButton)e.nextElement();
    				if(b.getModel() == group.getSelection()){
    					return b;
    				}
    
    		}return null;
    	}
    This basically checks all the buttons in the ButtonGroup that was passed in as the parameter and returns the one which is selected.

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Sun is suggesting that we use Iterator rather than Enumerator.

    Glad you were able to thaw your brain freeze.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center