首页 > 解决方案 > ScalaFX如何关闭二级

问题描述

如何关闭用作辅助窗口的二级阶段?所以我有一个primaryStage用作UI平台,偶尔我需要打开一个非常简单的辅助窗口,但是用一种方法关闭它还不清楚。

以下是第二阶段的参与方式:

val ivbox = new VBox(children = new Label("Create New Album"))
val stackpane = new StackPane()
sp.children = Seq(ivbox)

val secondstage = new Stage() {
  title = "second stage"
  scene = new Scene(stackpane, 450, 150) {
    stylesheets += getClass.getResource("uistyle.css").toExternalForm
  }
  x = myproto.stage.x.value + 200  // position in relation to primaryStage / scene
  y = myproto.stage.y.value + 100  //
}

在 JavaFX 中,我发现了这个片段:

private void closeButtonAction(){
    Stage stage = (Stage) closeButton.getScene().getWindow();
    stage.close();
}

不清楚如何在 ScalaFx 中获得?

标签: scalafx

解决方案


ScalaFX 没有区别。您使用close(). ScalaFX 中的代码完全相同:

stage.close()

推荐阅读