How to change the text font size in javafx?

梦想与她 提交于 2020-01-02 03:24:11

问题


I am making a project in javafx. As part of it I created a warning box. Its text font size is too small. The code of the warning box is :

Stage dialogStage = new Stage();
dialogStage.initStyle(StageStyle.UTILITY);
dialogStage.setScene(new Scene(VBoxBuilder.create().
children(new Text("Username or Password Error...!\n"
              + "Please Enter Correct Details...")).
alignment(Pos.CENTER).padding(new Insets(15,15,15,15)).build()));
dialogStage.show();

How can I change or increase the text font size ?


回答1:


I just did this:

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.VBoxBuilder;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;


public class TextApp extends Application
{

@Override
public void start(Stage primaryStage)
{

    final Text caption = new Text("Username or Password Error...!\n"
        + "Please Enter Correct Details...");
    caption.setFill(Color.BLACK);
    caption.setStyle("-fx-font: 24 arial;");


    Stage dialogStage = new Stage();
    dialogStage.initStyle(StageStyle.UTILITY);
    dialogStage.setScene(new Scene(VBoxBuilder.create().children(caption).alignment(Pos.CENTER)
        .padding(new Insets(15, 15, 15, 15)).build()));
    dialogStage.show();
}

public static void main(String[] args)
{
    launch(args);
}
}   



回答2:


You can use CSS to do that.

Check if code here is useful: https://gist.github.com/jewelsea/1887631

Something like this:

.modal-dialog {
    -fx-padding: 20;
    -fx-spacing: 10;
    -fx-alignment: center;
    -fx-font-size: 20;
}

and then apply it.



来源:https://stackoverflow.com/questions/22047457/how-to-change-the-text-font-size-in-javafx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!