에 할당 창 내에서 내 모달 윈도 객체를 닫으면, 중요한 사람이 여기에있는 :내가 그것을
show();
hide();
getContent();
setContent(Pane p);
내가 모달 윈도의 인스턴스를 생성, 나는 setContent (...); 미리 지정된 Pane 객체 (ModalWindow 인스턴스 생성 후 생성 된 객체)를 사용하여 show();를 호출합니다. hide(); 방법은, 공개적으로 액세스 할 수 있지만, 일반적으로 미리 생성 된 창 내에서 호출 - 난 (같은)
getPane(ModalWindow mW);
내가 (숨기기에 액세스 할 수 있도록 내가 이렇게)라는 다른 방법을 사용하여이 작업을 수행; 내 창은 일반적으로 모달 윈도를 종료하는 데 사용되는 버튼이 있습니다 내 경우에는 창 개체 내에서 기능 (, 내가 지금, 그래서
closeButton.setOnMouseClicked(event -> mW.hide());
를 사용하여이 작업을 수행, 모달 윈도의 내 인스턴스의 대부분은 다음과 같이 :
를
ModalWindow mW = new ModalWindow();
mW.setContent(getPane(mW));
mW.show(); // ModalWindow usually closed from within itself
내가 궁금하네요 것은 다음 모달 윈도가 창이 포함되고 있음을 개체에 액세스하는 반사 (또는 성격의 무언가를) 사용하는 방법 (생성 후 창 객체를 생성하지 않고있다 ModalWindow 인스턴스)?
다음은 전체입니다.
PaneHolder paneHolder = new PaneHolder();
ModalWindow mw = new ModalWindow(paneHolder);
및 닫기 버튼이 작동을 예 :
public class Main {
public static void main(String[] args) {
ModalWindow mW = new ModalWindow();
mW.setContent(PaneHolder.getPane(mW));
mW.show();
}
}
public class ModalWindow {
StackPane centeringPane = new StackPane();
private BooleanProperty showing = new SimpleBooleanProperty(false);
public ModalWindow() {
centeringPane.setOpacity(0);
centeringPane.setAlignment(Pos.CENTER);
}
public ModalWindow(Pane content) {
centeringPane.setOpacity(0);
centeringPane.setAlignment(Pos.CENTER);
setContent(content);
}
public void show() {
centeringPane.setVisible(true);
}
public void hide() {
centeringPane.setVisible(false);
}
public boolean isShowing() {
return showing.get();
}
public BooleanProperty showingProperty() {
return showing;
}
public void setShowing(boolean showing) {
this.showing.set(showing);
}
public Pane getContent() {
return (Pane) centeringPane.getChildren().get(0);
}
public void setContent(Pane content) {
centeringPane.getChildren().clear();
centeringPane.getChildren().add(content);
}
}
public class PaneHolder {
Pane getPane(ModalWindow mW) {
Pane p = new Pane();
Button closeButton = new Button("Close");
closeButton.setOnAction(event -> mW.hide()); // I need the reference to mW here
p.getChildren.add(closeButton);
return p;
}
}
간단히 말해서, 객체가 객체에 대한 참조를 보유하고있는 다른 객체를 발견 할 수있는 방법이 없습니다 (생각합니다.). (어쨌든 단 하나의 'ModalWindow'만 있다는 것을 어떻게 확신 할 수 있겠는가?) 아마도 실제 코드를 게시 할 수 있을까? –
@James_D 전체 예제를 추가했으나 현재 얻고있는 것을 봅니다. –