javafx fxml将窗口带到前面的窗体

时间:2015-04-09 07:06:35

标签: javafx fxml scene

我需要从自己前面JavaFX FXML窗口。像这样:

procedure (boolean close)
{
   if(close)
     current_window.toFront();
}

我应该如何获得此窗口(场景)?

2 个答案:

答案 0 :(得分:0)

试试这个

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Main extends Application {

@Override
public void start(Stage stage) {
    Text text = new Text("!");
    text.setFont(new Font(40));
    VBox box = new VBox();
    box.getChildren().add(text);
    final Scene scene = new Scene(box,300, 250);
    scene.setFill(null);
    stage.setScene(scene);
    stage.show();
    stage.toFront();
}

public static void main(String[] args) {
    launch(args);
}
}

答案 1 :(得分:0)

如果您有权访问任何节点,则可以使用以下

((Stage)node.getScene().getWindow()).toFront();
相关问题