1
需要顯示JavaFX 2中顯示和隱藏窗口的示例。如何在JavaFX 2中顯示和隱藏窗口?
需要顯示JavaFX 2中顯示和隱藏窗口的示例。如何在JavaFX 2中顯示和隱藏窗口?
A stage
是javafx-2中的一個窗口。它提供hide和show方法:
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();
}
}
是否可以完全隱藏窗口? – Hrvoje 2013-08-28 11:31:44
是的,請嘗試此答案的代碼示例。 – gontard 2013-08-28 13:38:54
一個階段是JavaFX中的一個窗口,但在API中注意到JavaFX中的一個階段的'hide()'函數等價於'close()'函數 – 2017-05-31 02:27:36