0
Oracle 데모 페이지에서 라디오 버튼과 이벤트 리스너를 사용할 수 있습니다. 그것은 작동한다, 그것은 데이터를 db에 저장하지만, 문제는 그룹에 라디오가있는 것처럼 여러 번 발사된다는 것이다. 한 번만 데이터를 처리 할 수 있도록 한 번만 토글하고 싶습니다.JavaFX 라디오 버튼 이벤트를 한 번만 실행하십시오.
여기에 관련 코드입니다 (나는지도를 사용하고, 그래서 나는 많은 라디오 그룹이 주) :
private Map<Integer, RadioButton> Radios = new HashMap<>();
private Map<Integer, ToggleGroup> RadioGroups = new HashMap<>();
(...)
DrawRadio (int group, int id, String label) {
if (RadioGroups.get(group) == null) {
RadioGroups.put(group, new ToggleGroup());
}
(...)
Radios.put(id, new RadioButton(label));
Radios.get(id).setToggleGroup(RadioGroups.get(group));
Radios.get(id).setUserData(ans_id);
(...)
RadioGroups.get(group).selectedToggleProperty().addListener(new ChangeListener<Toggle>(){
public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
if (RG.getSelectedToggle().equals(new_toggle)) {
System.out.println ("Called with ov:" + ov + ", old_tgl:" + old_toggle.toString() + " and new_tgl: " + new_toggle.toString());
}
}
}
}
그리고 출력을 내가 A에서 B로 라디오를 선택 변경하면 것은 :
Called with ov:ReadOnlyObjectProperty [value: [email protected][styleClass=radio-button]'b'], old_tgl:[email protected][styleClass=radio-button]'a' and new_tgl: [email protected][styleClass=radio-button]'b'
Called with ov:ReadOnlyObjectProperty [value: [email protected][styleClass=radio-button]'b'], old_tgl:[email protected][styleClass=radio-button]'a' and new_tgl: [email protected][styleClass=radio-button]'b'
Called with ov:ReadOnlyObjectProperty [value: [email protected][styleClass=radio-button]'b'], old_tgl:[email protected][styleClass=radio-button]'a' and new_tgl: [email protected][styleClass=radio-button]'b'
Called with ov:ReadOnlyObjectProperty [value: [email protected][styleClass=radio-button]'b'], old_tgl:[email protected][styleClass=radio-button]'a' and new_tgl: [email protected][styleClass=radio-button]'b'
Called with ov:ReadOnlyObjectProperty [value: [email protected][styleClass=radio-button]'b'], old_tgl:[email protected][styleClass=radio-button]'a' and new_tgl: [email protected][styleClass=radio-button]'b'
내가 그렇게, 그것은 단지 일단 싶습니다 :
Called with ov:ReadOnlyObjectProperty [value: [email protected][styleClass=radio-button]'b'], old_tgl:[email protected][styleClass=radio-button]'a' and new_tgl: [email protected][styleClass=radio-button]'b'
내가 문제를 복제하려고했지만 할 수 없었다 다음을 radioGroup은 (처음으로) 생성되는 경우
수정 체크를 추가하는 것입니다. 나는 당신이 당신의 코드에서 무엇을하는지보고 싶다. 이 작업을 위해 [MCVE] (http://stackoverflow.com/help/mcve)를 만들 수 있습니까? – ItachiUchiha
'RadioGroups.get (group) ... '코드를 디버그하십시오. 동일한 속성에 동일한 수신기를 두 번 이상 추가 할 수 있습니다. –
그래, 그게 문제 였어 - 내가 DrawRadio를 부를 때마다 나는 이벤트 리스너를 추가했다! – May11