I have a JMenu with some radio buttons...For some reason, when I click the stupid things, they won't do anything...and by that, I mean they want change their state to being clicked(as in the circle being filled)..It's like they are disabled...I'll post the snippets of code with them in it:

JMenu formatMenu = new JMenu("Format");
		ButtonGroup bg = new ButtonGroup();	
		rb0 = new JRadioButton("###",false);
		rb0.addActionListener(this);
		rb2 = new JRadioButton("###.##",true);	
		rb2.addActionListener(this);
		rb4 = new JRadioButton("###.####",false);
		rb4.addActionListener(this);	
		rb6 = new JRadioButton("###.######",false);
		rb6.addActionListener(this);
		
		bg.add(rb0);
		bg.add(rb2);
		bg.add(rb4);
		bg.add(rb6);
		formatMenu.add(rb0);
		formatMenu.add(rb2);
		formatMenu.add(rb4);
		formatMenu.add(rb6);

Why would I not be able to click these buttons?

Post the whole thing and i'll tell you

It's like 550 lines of code...but if you want it, you got it...

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

import javax.swing.undo.*;
import javax.swing.event.*;
import javax.swing.text.*;

import java.text.*;

public class Calculator extends JFrame implements ActionListener, UndoableEditListener
{
	JMenuItem exit;
	JMenuItem clear;
	JMenuItem copy;
	JMenuItem paste;
	JMenuItem undo;
	JMenuItem redo;
	JMenuItem aboutCalc;

	JRadioButton rb0;
	JRadioButton rb2;
	JRadioButton rb4;
	JRadioButton rb6;
	JRadioButton rb8;

	
	JButton[] btnNums;
	JButton btnBack;
	JButton btnClear;
	JButton btnAddMem;
	JButton btnPasteMem;
	JButton btnCalculate;
	String[] strNames;
	String strOperand1;
	String strOperand2;
	double dOperand1;
	double answer;
	double memoryVar;
	int operatorCount = 0;

	final String STR_MULTIPLY = "MULTIPLY";
	final String STR_DIVIDE = "DIVIDE";
	final String STR_ADD = "ADD";
	final String STR_SUBTRACT = "SUBTRACT";
	final String STR_SQUARE = "SQUARE";

	String whichOperator;
	DecimalFormat dec;
	Document doc;
	
	
	JTextField txtDisplay;
	ArrayList operands;
	
	UndoManager undoManager;	
	public Calculator()
	{
		
		JPanel menuPanel = new JPanel();
		BorderLayout br = new BorderLayout();
		
		JMenuBar menuBar = new JMenuBar();
		
		JMenu fileMenu = new JMenu("File");
		fileMenu.add(exit = new JMenuItem("Exit"));
		exit.addActionListener(this);
		
		JMenu editMenu = new JMenu("Edit");
		editMenu.add(undo = new JMenuItem("Undo"));
		undo.addActionListener(this);
		editMenu.add(redo = new JMenuItem("Redo"));
		redo.addActionListener(this);
		editMenu.add(copy = new JMenuItem("AddM"));
		copy.addActionListener(this);
		editMenu.add(paste = new JMenuItem("PasteM"));
		paste.addActionListener(this);
		editMenu.add(clear = new JMenuItem("Clear"));
		clear.addActionListener(this);
		
		JMenu formatMenu = new JMenu("Format");
		ButtonGroup bg = new ButtonGroup();	
		rb0 = new JRadioButton("###",false);
		rb0.addActionListener(this);
		rb2 = new JRadioButton("###.##",true);	
		rb2.addActionListener(this);
		rb4 = new JRadioButton("###.####",false);
		rb4.addActionListener(this);	
		rb6 = new JRadioButton("###.######",false);
		rb6.addActionListener(this);
		
		bg.add(rb0);
		bg.add(rb2);
		bg.add(rb4);
		bg.add(rb6);
		formatMenu.add(rb0);
		formatMenu.add(rb2);
		formatMenu.add(rb4);
		formatMenu.add(rb6);
		
		JMenu aboutMenu = new JMenu("About");
		aboutMenu.add(aboutCalc = new JMenuItem("About Calculator"));
		aboutCalc.addActionListener(this);
		
		menuBar.add(fileMenu);
		menuBar.add(editMenu);
		menuBar.add(formatMenu);
		menuBar.add(aboutMenu);
		setJMenuBar(menuBar);
		
		undoManager = new UndoManager();
		undoManager.setLimit(1500);
		
		
		/*  construct a JPanel and the textfield that 
		 *  will show the inputed values and outputed 
		 *  results
		 */
		JPanel jpDisplay = new JPanel();
		jpDisplay.setLayout(new BorderLayout());
		txtDisplay = new JTextField(15);
		txtDisplay.setHorizontalAlignment(JTextField.RIGHT);
		doc = (Document)txtDisplay.getDocument();
		doc.addUndoableEditListener(this);
		jpDisplay.add(txtDisplay);
		
		dec = new DecimalFormat("###,###,###.##");
		
		/*  contstruct a JPanel that will contain a back
		 *  button and a clear button.
		 */
		JPanel jpRow2 = new JPanel();
		btnAddMem = new JButton("M+");
		btnAddMem.addActionListener(this);
		btnPasteMem = new JButton("M-");
		btnPasteMem.addActionListener(this);
		btnBack = new JButton("back");
		btnBack.addActionListener(this);
		
		jpRow2.add(btnAddMem);
		jpRow2.add(btnPasteMem);
		jpRow2.add(btnBack);
		
		
		
		
		
		/*  construct a string array with all the names of the
		 *  buttons, then in a for loop create the new buttons
		 *  and add their name and an actionListener to them.
		 */
		String[] strNames = {"7","8", "9","/", "4", "5", "6","*", "1",
					   "2", "3","+", "0", "^", ".", "-"};
		btnNums = new JButton[16];
		JPanel jpButtons = new JPanel();
		jpButtons.setLayout(new GridLayout(4,4,4,4));
		
		  for (int i = 0; i < 16; i++)
		  {
			  btnNums[i] = new JButton(strNames[i]);
			  btnNums[i].addActionListener(this);
			  jpButtons.add(btnNums[i]);
		  }
		  
		  /*  construct the final JPanel and add a 
		   *  calculate button to it.
		   */
		  JPanel jpLastRow = new JPanel();
		  btnCalculate = new JButton("calculate");
		  btnCalculate.addActionListener(this);
		  btnClear = new JButton("clear");
		  btnClear.addActionListener(this);
		  jpLastRow.add(btnCalculate);
		  jpLastRow.add(btnClear);
		  
		  
		  operands = new ArrayList();
		  /*  set the contentPane and create the layout
		   *  add the panels to the container
		   */
		  Container content = getContentPane();
		  setSize(240,290);
		  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		  setContentPane(content);
		  setLayout(new FlowLayout());
		  setResizable(false);
		  content.add(menuPanel, BorderLayout.NORTH);
		  content.add(jpDisplay, BorderLayout.NORTH);
		  content.add(jpRow2);
		  content.add(jpButtons);
		  content.add(jpLastRow);
		  setTitle("Mini Calculator");
		  setVisible(true); 
		  
	}
	
 
      public void undoableEditHappened(UndoableEditEvent uee)
	{
		undoManager.addEdit(uee.getEdit());
   	}
		
	public void actionPerformed(ActionEvent ae)
	{
		// if any of the array buttons was clicked append the button's text
		for (int i =0; i < 16; i++)
		{
			if (ae.getSource() == btnNums[i])
			{
				txtDisplay.setText(txtDisplay.getText()
						+ btnNums[i].getText());
				
			}
		}
		
		
		/*  if the backspace button was clicked, then create substring
		 *  to to subtract the farthest character to the right
		 */
		if (ae.getSource() == btnBack)
		{
			String strAll = txtDisplay.getText();
			int length = strAll.length();
			String strShowThis = strAll.substring(0,length - 1);
			txtDisplay.setText(strShowThis);
		}
			else if (ae.getSource() == btnClear || ae.getSource() == clear)
			{
				txtDisplay.setText(null);
				operatorCount = 0;
			}	
			else if (ae.getSource() == btnCalculate)
			{
				String strText = txtDisplay.getText();
				try 
				{
					int equation = Integer.parseInt(strText);
					txtDisplay.setText("" + equation);
				}
				catch (ArithmeticException aee)
				{
					aee.printStackTrace();
		 	        }
			}
			 else if (ae.getSource() == btnAddMem || ae.getSource() == copy)
			 {
				 memoryVar = Double.parseDouble(txtDisplay.getText());
			
			}
			else if (ae.getSource() == btnPasteMem || ae.getSource() == paste)
			{
				txtDisplay.setText(memoryVar + "");
			}
			else if (ae.getSource() == exit)
			{
				System.exit(0);
			}
			
			/*  start the process of finding which operator was 
			 *  chosen, and the process the equation in a new 
			 *  method
			 */
			 
			 if (ae.getSource() == btnNums[3])
			 {
				 processDivide();
			 }
			 else if (ae.getSource() == btnNums[7])
			 {
				 processMultiply();
			 }
			 else if (ae.getSource() == btnNums[11])
			 {
				 processAdd();
			 }
			 else if (ae.getSource() == btnNums[13])
			 {
				processSquare();
			 }
			 else if (ae.getSource() == btnNums[15])
			 {
				 processSubtract();
			 }
			 else if (ae.getSource() == undo)
			 {
				 processUndo();
			 }
			 else if (ae.getSource() == redo)
			 {
				 processRedo();
			 }
			 else if (ae.getSource() == aboutCalc)
			 {
				 processAbout();
			 }
			 else
			 {
			 }

			if (ae.getSource() == rb0)
			{
				dec = new DecimalFormat("###,###,###.0");
			}
			else if (ae.getSource() == rb2)
			{
				dec = new DecimalFormat("###,###,###.##");
			}
			else if (ae.getSource() == rb4)
			{
				dec = new DecimalFormat("###,###,###.####");
			}
			else if (ae.getSource() == rb6)
			{
				dec = new DecimalFormat("###,###,###.######");
			}
			else
			{
			}

		// and finally process the calculation
		if (ae.getSource() == btnCalculate)
		{
			processCalc();
		}
		else
		{
		}
	}
	
	public void processDivide()
	{
		operatorCount += 1;
	  if (operatorCount == 1)
	  {
		whichOperator = STR_DIVIDE;
		strOperand1 = txtDisplay.getText();
		int x = strOperand1.length();
		String s = strOperand1.substring(0, x - 1);
		dOperand1 = Double.parseDouble(s);
		txtDisplay.setText(null);
	  }
	  else if (operatorCount > 1)
	  {	
		whichOperator = STR_DIVIDE;
		strOperand2 = txtDisplay.getText();
		int x = strOperand2.length();
		String s = strOperand2.substring(0, x-1);
		double d = Double.parseDouble(s);
		dOperand1 = dOperand1 / d;
		txtDisplay.setText("");
	  }
	  else 
	  {
	  }
	  
	}
	public void processMultiply()
	{
		operatorCount += 1;
	   if (operatorCount == 1)
	   {
		whichOperator = STR_MULTIPLY;
		strOperand1 = txtDisplay.getText();
		int x = strOperand1.length();
		String s = strOperand1.substring(0, x - 1);
		dOperand1 = Double.parseDouble(s);
		txtDisplay.setText(null);
	     }
	  else if (operatorCount > 1)
	  {
		whichOperator = STR_MULTIPLY;
		strOperand2 = txtDisplay.getText();
		int x = strOperand2.length();
		String s = strOperand2.substring(0, x-1);
		double d = Double.parseDouble(s);
		dOperand1 = dOperand1 * d;
		txtDisplay.setText("");
	  }
	  else 
	  {
	  }
	}
	public void processAdd()
	{
		operatorCount += 1;
	   if  (operatorCount == 1)
	   {
		whichOperator = STR_ADD;
		strOperand1 = txtDisplay.getText();
		int x = strOperand1.length();
		String s = strOperand1.substring(0, x -1);
		dOperand1 = Double.parseDouble(s);
		txtDisplay.setText(null);
		  }
	  else if (operatorCount > 1)
	  {
		whichOperator = STR_ADD;
		strOperand2 = txtDisplay.getText();
		int x = strOperand2.length();
		String s = strOperand2.substring(0, x-1);
		double d = Double.parseDouble(s);
		dOperand1 = dOperand1 + d;
		txtDisplay.setText("");
	  }
	  else
	  {
	  }
	}

	public void processSubtract()
	{
		operatorCount += 1;
	   if (operatorCount == 1)
	   {
		whichOperator = STR_SUBTRACT;
		strOperand1 = txtDisplay.getText();
		int x = strOperand1.length();
		String s = strOperand1.substring(0, x - 1);
		dOperand1 = Double.parseDouble(s);
		txtDisplay.setText(null);
	     }
	  else if (operatorCount > 1)
	  {
		whichOperator = STR_SUBTRACT;
		strOperand2 = txtDisplay.getText();
		int x = strOperand2.length();
		String s = strOperand2.substring(0, x-1);
		double d = Double.parseDouble(s);
		dOperand1 = dOperand1 - d;
		txtDisplay.setText("");
	  }
	  else 
	  {
	  }
	}

	public void processSquare()
	{
		whichOperator = STR_SQUARE;
		strOperand1 = txtDisplay.getText();
		int x = strOperand1.length();
		String s = strOperand1.substring(0,x-1);
		dOperand1 = Double.parseDouble(s);
		txtDisplay.setText("");
	}

	public void processCalc()
	{
	

		strOperand2 = txtDisplay.getText();
		int x = strOperand2.length();
		String s = strOperand2.substring(0, x);
		double d = Double.parseDouble(s);
		
		if (whichOperator == STR_SUBTRACT)
		{
			double answer = dOperand1 - d;
			txtDisplay.setText("" + dec.format(answer));
		}
		else if (whichOperator == STR_ADD)
		{
			double answer = dOperand1 + d;
			txtDisplay.setText("" + dec.format(answer));
		}
		else if (whichOperator == STR_MULTIPLY)
		{
				answer = dOperand1 * d;
			txtDisplay.setText("" + answer);
		}
		else if (whichOperator == STR_DIVIDE)
		{
				answer = dOperand1 / d;
			txtDisplay.setText("" + dec.format(answer));
		}
		else if (whichOperator == STR_SQUARE)
		{
			String o2 = txtDisplay.getText();
			Double d2 = Double.parseDouble(o2);
			answer = Math.pow(dOperand1,d2);
			txtDisplay.setText("" + dec.format(answer));
		}
	
		operatorCount = 0;
	
	}
	
	public void processUndo()
	{
		 try
		 {
			 /* call the UndoManagers undo method
			  */
			 undoManager.undo();
		 }
		 catch (CannotUndoException cre)
		 {
		 }

	}
	public void processRedo()
	{
		 try 
	 {
		 /*  call the UndoManagers redo() method
		  */
		 undoManager.redo();
	 }
	 catch (CannotRedoException cre)
	 {
	 }

	}
	public void processAbout()
	{
 		String message = "Written and Tested by: Cantley Sheppard" + "\nDate Developed: Febuary 8th, 2005\n"
									+ " Copyright 2005\n All rights reserverd";
		JOptionPane.showMessageDialog(null, message);
	}

	public static void main(String[] args)
	{
		Calculator calc = new Calculator();
	}
}

Now, there is a few other problems with it, but I'm only interested in getting the JRadioButton thing fixed..Just run the program, and try to select something from the format menu..

I fixed it...Using JRadioButtonMenuItem worked..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.