【发布时间】:2021-07-10 21:01:43
【问题描述】:
您熟悉“按 esc 退出全屏”消息。
在JavaFX中,有方法:
Stage stage = new Stage();
stage.setFullScreenExitHint("whatever you want it to say, instead of 'press esc to exit full screen.');
我使用它来向用户显示指导性消息,只是因为它非常简单、预制、格式良好,并且在短时间内消失。效果很好,但可能在 15 个字之后文本溢出:
我认为可以通过设置字体大小来修复它。在 JavaFX 中,您可以通过
Node node = new Node();
node.setStyle("-fx-font-size:___pt");//or px, rem, em.
如果可能的话,您如何更改该消息的样式?
请求的最小可重现示例:
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import java.io.IOException;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws IOException {
Parent root = new BorderPane();
primaryStage.setFullScreen(true);
primaryStage.setFullScreenExitHint("""
Welcome to Minesweeper. At left, you can alter the # of rows and columns. At right, set the # of mines. Play is bottom right.
_
""");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
【问题讨论】:
标签: javafx fullscreen font-size exit stage