0

I have GUI screen which lets you set the privacy of a Contact from a selection being made through RadioButton. Although I can add the selection to the database like this...

 private void addContactButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                 
        try {
            ContactDAO cDao = new ContactDAO();
            final ContactDTO cdto = new ContactDTO();


 String privacy = "";
            String alumni = "";
            if (all.isSelected()) {
                privacy = all.getText();
            }
            if (bio.isSelected()) {
                privacy = bio.getText();
            }
            if (none.isSelected()) {
                privacy = none.getText();
            }
            if (yes.isSelected()) {
                alumni = yes.getText();
            }
            if (no.isSelected()) {
                alumni = no.getText();
            }
            cdto.setAlumni(alumni);
            cdto.setStatus(privacy);
            cDao.add(cdto); 

}

I am stuck on retrieving the previously selected item for edit mode. Each radiobutton option belong to a buttongroup.

private void editContact() {
    txtID1.setText(String.valueOf(cDTO.getID()));
    txtTitle1.setText(cDTO.getTitle());
    txtFn1.setText(cDTO.getForename());
    txtSn1.setText(cDTO.getSurname());
    //get status from cDTO.getStaus and adjust appropriately to the radio button
}

in the above method I would like to set the selected item of the radio button. Just as you would do getSelectedItem() for JComboBox, I am trying to achieve the same for radio button. note cDTO contains the data string, cDTO.getStatus which gets the value from database. But how do I set it to the 3 radio buttons that i have, named allButton bioButton noneButton

Hoody
  • 2,942
  • 5
  • 28
  • 32
  • 1
    for better help sooner post an [SSCCE](http://sscce.org/), short, runnable, compilable, just about a.m. issue – mKorbel Apr 02 '13 at 10:40

1 Answers1

1

Assuming that cDTO.getStatus() returns a String that matches a radio button's name: For each button in the ButtonGroup, b, do something like this:

b.setSelected(cDTO.getStatus().equals(b.getText()));
trashgod
  • 203,806
  • 29
  • 246
  • 1,045