그래서이 JavaFX 응용 프로그램에는 DirectoryChooser onclick을 여는 데 필요한 단추가 들어 있습니다. 내가 한번 방아쇠를 당길 때, 그것은 그것이해야 할 일을, 완벽하게 잘합니다. DirectoryChooser 대화 상자를 닫으면 버튼이 더 이상 아무것도하지 않습니다. 난 내가 이벤트가 더 이상 실행되지 않고 여전히 "활성"이고, 따라서 어쩌면 생각했기 때문에, 일부 "이벤트 재설정"또는 유사한 무언가를 위해 웹 검색 되었으나, 결과가없는 :이 경우JavaFX 단추 이벤트는 한 번만 트리거됩니다.
// first attempt
button.addEventFilter(MouseEvent.MOUSE_CLICKED,
new EventHandler<MouseEvent>() {
public void handle(MouseEvent e) {
// dirChooser.setTitle("Select Directory:");
file = dirChooser.showDialog(primaryStage);
// just incase only the DirectoryChooser wasn't opening
System.out.println("asdf");
// updates the application view with the new selected path
update();
// not sure, if this affects anything
// found it while looking for resetting of events
e.consume();
};
}
);
// secont attempt
button.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
DirectoryChooser dirChooser = new DirectoryChooser();
dirChooser.setTitle("Select Directory:");
file = dirChooser.showDialog(primaryStage);
update();
}
});
확실하지 않음 단지 완전히 잘못된 접근이거나, 내가 거기에서 중요한 것을 놓치고 있다면. 사람들이 알아낼 수 있기를 바랍니다.
"버튼이 더 이상 아무것도하지 않는다"는 것은 무엇을 의미합니까? 두 번째 및 이후 클릭에 대해 이벤트 핸들러가 트리거되지 않습니까? –
글쎄, DiaglogChooser가 열리지 않습니다. 콘솔 출력이 없습니다. 핸들 함수가 호출되지 않은 것처럼 보입니다. 그래서 예, 그것은 유발되지 않습니다. –
을 디버깅 용으로 사용하려면 코드에서 dirChooser (및 update()) 행을 주석 처리하고 다시 클릭하십시오. 콘솔 출력이 있습니까? –