How to change the text font size in javafx?


Question

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
5
2/26/2014 4:32:23 PM

Accepted Answer

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);
}
}   
7
2/26/2014 7:02:24 PM

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.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon