If your buttons are in a ButtonGroup, you can call the getButtonCount() method (ButtonGroup (Java Platform SE 6))