Skip to content

Instantly share code, notes, and snippets.

@xnrghzjh
Created June 16, 2011 01:01
Show Gist options
  • Save xnrghzjh/1028490 to your computer and use it in GitHub Desktop.
Save xnrghzjh/1028490 to your computer and use it in GitHub Desktop.
ボタングループから選択されているラジオボタンのキャプションを取得
private buttonGroup = new javax.swing.ButtonGroup();
private button1 = new javax.swing.JRadioButton();
private button2 = new javax.swing.JRadioButton();
private button3 = new javax.swing.JRadioButton();
buttonGroup.add(button1);
buttonGroup.add(button2);
buttonGroup.add(button3);
public String getSelectedButtonCaption() {
String value = "";
Enumeration<AbstractButton> ite = buttonGroup.getElements();
while (ite.hasMoreElements()) {
AbstractButton button = ite.nextElement();
if (button.isSelected()) {
value = button.getText();
break;
}
}
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment