我无法从单选按钮中获取文本,以便在选择文本区域时显示。只能得到真值或假值。下面的代码是我遇到问题的地方。我很感激任何建议。
jTextArea2.setText(String.valueOf("Mixed Flavors:" + jRadioButton1.isSelected() + jRadioButton2.isSelected()
+ jRadioButton3.isSelected() + jRadioButton4.isSelected()));
答案 0 :(得分:3)
获取文本您必须在radiobutton上使用getText()
。此外,不需要使用String.valueOf()
,因为您尝试在TextArea中设置的整个内容将变为String。
jTextArea2.setText("Mixed Flavors:" + jRadioButton1.getText() + ":" +
jRadioButton1.isSelected() + " , " + jRadioButton2.getText() + ":" +
jRadioButton2.isSelected() + " , "+ jRadioButton3.getText() + ":" +
jRadioButton3.isSelected() + " , " + jRadioButton4.getText() + ":" +
jRadioButton4.isSelected());
答案 1 :(得分:1)
我无法从单选按钮中获取文本,以便在选中文本区域时显示,我只是希望这意味着您想尝试类似
的内容if( jRadioButton1.isSelected() )
jTextArea2.setText( String.valueOf("BLA") + jRadioButton1.getText() );
if( jRadioButton2.isSelected() )
jTextArea2.setText( String.valueOf("BLA") + jRadioButton2.getText() );
if( jRadioButton3.isSelected() )
jTextArea2.setText( String.valueOf("BLA") + jRadioButton3.getText() );
if( jRadioButton4.isSelected() )
jTextArea2.setText( String.valueOf("BLA") + jRadioButton4.getText() );