두 개의 JRadioButton이있는 jframe이 있습니다.JRadionButton이 자동으로 선택 해제됩니다.
public class jradioButtontest extends javax.swing.JFrame {
public jradioButtontest() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jRadioButton1.setText("jRadioButton1");
jRadioButton2.setText("jRadioButton2");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(198, 198, 198)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jRadioButton2)
.addComponent(jRadioButton1))
.addContainerGap(203, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(80, 80, 80)
.addComponent(jRadioButton1)
.addGap(18, 18, 18)
.addComponent(jRadioButton2)
.addContainerGap(225, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new jradioButtontest().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
// End of variables declaration
}
나는 내가 처음 JRadioButton의를 선택하면, 다른 JRadioButton의 선택되지 않은해야합니다. 준비된 jframe을 사용하여 netbeans 생성 코드를 어떻게 변경할 수 있습니까? 어떻게하면 되나요?
당신은 단지 [라디오 버튼 튜토리얼]을 확인하는 것을 알고있다 (http://docs.oracle.com/javase/tutorial/uiswing/components/button.html#radiobutton) 것 "각 라디오 버튼 그룹에 대해 ButtonGroup 인스턴스를 만들고 각 라디오 버튼을 추가해야합니다. ButtonGroup은 사용자가 다른 버튼을 선택할 때 이전에 선택한 버튼을 선택 취소합니다. 그룹 " – Robin