如何在JavaFX 2中显示和隐藏窗口? [英] How to show and hide a window in JavaFX 2?
本文介绍了如何在JavaFX 2中显示和隐藏窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要显示一个示例,您可以在其中显示和隐藏JavaFX 2中的窗口.
Need to show an example in which you show and hide a window in JavaFX 2.
推荐答案
stage
是javafx-2中的一个窗口.它提供了隐藏和显示方法:>
A stage
is a window in javafx-2. It provide the hide and show methods:
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class HideShowApp extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
final Stage window = new Stage();
window.setX(10);
Scene innerScene = new Scene(new Label("inner window"));
window.setScene(innerScene);
HBox root = new HBox(10d);
Button showButton = new Button("show");
showButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
window.show();
}
});
Button hideButton = new Button("hide");
hideButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
window.hide();
}
});
root.getChildren().add(showButton);
root.getChildren().add(hideButton);
stage.setScene(new Scene(root));
stage.show();
}
}
这篇关于如何在JavaFX 2中显示和隐藏窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文