Вот часть моего кода FXML, определяющая VBox и метку:
Код: Выделить всё
Код: Выделить всё
.label-resultado {
-fx-text-fill: #ffffff;
-fx-font-size: 70;
-fx-font-family: 'Hind Siliguri Medium';
}
.label-review {
-fx-text-fill: #ffffff;
-fx-font-size: 24;
-fx-font-family: 'Hind Siliguri Medium';
}
Код: Выделить всё
public class HelloController {
private static final double FONT_MIN_SIZE_RESULTADO = 70;
private static final double FONT_MIN_SIZE_REVIEW = 24;
public void inicializarStage(Stage stage) {
stage.widthProperty().addListener((obs, oldWidth, newWidth) -> ajustarFonte(stage));
stage.heightProperty().addListener((obs, oldHeight, newHeight) -> ajustarFonte(stage));
System.out.println(stage.getWidth()+" "+stage.getHeight());
}
private void ajustarFonte(Stage stage) {
double width= stage.getWidth();
double height= stage.getHeight();
// Escala de acordo com a janela atual, considerando 400x800 como base
double scaleWidth = width/ 360.6;
double scaleHeight = height / 677.0;
double novaFonteResultado = Math.max(FONT_MIN_SIZE_RESULTADO, FONT_MIN_SIZE_RESULTADO * Math.min(scaleWidht, scaleHeight));
double novaFonteReview = Math.max(FONT_MIN_SIZE_REVIEW, FONT_MIN_SIZE_REVIEW * Math.min(scaleWidht, scaleHeight));
resultadoTexto.setStyle("-fx-font-size: " + novaFonteResultado + "px;");
reviewTexto.setStyle("-fx-font-size: " + novaFonteReview + "px;");
}
Код: Выделить всё
public class HelloController {
private static final double FONT_MIN_SIZE_RESULTADO = 70;
private static final double FONT_MIN_SIZE_REVIEW = 24;
private void initialize() {
resultadoTexto.setStyle("-fx-font-size: " + FONT_MIN_SIZE_RESULTADO + "px;");
reviewTexto.setStyle("-fx-font-size: " + FONT_MIN_SIZE_REVIEW + "px;");
}
public void inicializarStage(Stage stage) {
stage.widthProperty().addListener((obs, oldWidth, newWidth) -> ajustarFonte(stage));
stage.heightProperty().addListener((obs, oldHeight, newHeight) -> ajustarFonte(stage));
System.out.println(stage.getWidth()+" "+stage.getHeight());
}
private void ajustarFonte(Stage stage) {
double width= stage.getWidth();
double height= stage.getHeight();
// Escala de acordo com a janela atual, considerando 400x800 como base
double scaleWidth = width/ 360.6;
double scaleHeight = height / 677.0;
double novaFonteResultado = Math.max(FONT_MIN_SIZE_RESULTADO, FONT_MIN_SIZE_RESULTADO * Math.min(scaleWidht, scaleHeight));
double novaFonteReview = Math.max(FONT_MIN_SIZE_REVIEW, FONT_MIN_SIZE_REVIEW * Math.min(scaleWidht, scaleHeight));
resultadoTexto.setStyle("-fx-font-size: " + novaFonteResultado + "px;");
reviewTexto.setStyle("-fx-font-size: " + novaFonteReview + "px;");
}
Нормальный размер
Размер изменен (см., что метки стали немного ниже)
Подробнее здесь: https://stackoverflow.com/questions/790 ... -font-size
Мобильная версия