동일한 이벤트 코드를 공유하는 ImageView 개체의 ID를 가져 오는 데 사용합니다. 여기
@FXML
private void selectImage(MouseEvent event)
{
String source1 = event.getSource().toString(); //yields complete string
String source2 = event.getPickResult().getIntersectedNode().getId(); //returns JUST the id of the object that was clicked
System.out.println("Full String: " + source1);
System.out.println("Just the id: " + source2);
System.out.println(" " + source2);
}
내가 '프레스에 마우스'는에 selectImage 방법을 지정하는 이벤트를 SceneBuilder를 사용하여 내 상황, 다음 코드를 실행하고 무작위로 삼을 클릭의 출력 : 여기 된 MouseEvent를 사용하여 간단한 예입니다 다른 이미지 뷰 객체 :
Full String: ImageView[id=iv1, styleClass=image-view] Just the id: iv1
Full String: ImageView[id=iv4, styleClass=image-view] Just the id: iv4
Full String: ImageView[id=iv6, styleClass=image-view] Just the id: iv6
나는이 사람을 도움이되기를 바랍니다. :-)
버튼, 레이블 및 기타 컨트롤을 클릭 할 때'id' 또는'fx : id'를 가져 오시겠습니까? – ItachiUchiha
fx : id를 얻고 싶습니다. –
왜 fx : id를 컨트롤에 넣으시겠습니까? 'fx : id'는 컨트롤러의 컨트롤과 바인드하기 위해 fxml에서 사용됩니다. 'fx : id'를 얻는 것은 의미가 없습니다. fx : id를 가져 오는 이유를 알 수 있습니까? – ItachiUchiha