如何更改“按ESC退出全屏”

时间:2018-06-23 06:26:54

标签: java javafx

如何使用 setFullScreenExitHint

因为:无法解析方法'setFullScreenExitHint'

您有没有像setFullScreen更好的方法?

JDK:jdk1.8.0_171

package game;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class main extends Application {

@Override
public void start(Stage primaryStage) throws Exception {
    Parent parent = FXMLLoader.load(getClass().getResource("/view/login.fxml"));
    Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
    Scene scene = new Scene(parent, screenBounds.getWidth(), 
    screenBounds.getHeight());
    primaryStage.setFullScreen(true);

    primaryStage.setScene(scene);
    primaryStage.show();
}
}

1 个答案:

答案 0 :(得分:0)

这对我来说非常合适:

@Override
public void start(Stage primaryStage) throws Exception {
    Parent parent = FXMLLoader.load(getClass().getResource("/view/login.fxml"));
    Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
    Scene scene = new Scene(parent, screenBounds.getWidth(), 
    screenBounds.getHeight());
    primaryStage.setFullScreen(true);

    primaryStage.setScene(scene);
    primaryStage.setFullScreenExitHint("hello");
    primaryStage.show();
}

在JavaFX 8文档中:Stage

如果将退出键组合设置为KeyCombination.NO_MATCH,则弹出消息将被完全禁用。