Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the text font size in javafx?

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 ?

like image 762
TomJ Avatar asked Feb 26 '14 16:02

TomJ


People also ask

How do I make text bold in JavaFX?

Making Text Bold or Italic To make the text look bold, use the FontWeight constant of the font method as shown in Example 8. t. setFont(Font. font("Verdana", FontWeight.

How do you change the color of text in JavaFX?

If you are designing your Javafx application using SceneBuilder then use -fx-text-fill (if not available as option then write it in style input box) as style and give the color you want,it will change the text color of your Textfield .

What is StackPane in JavaFX?

StackPane lays out its children in a back-to-front stack. The z-order of the children is defined by the order of the children list with the 0th child being the bottom and last child on top. If a border and/or padding have been set, the children will be layed out within those insets.

How do you underline text in JavaFX?

Text class determines whether each line of the text should have a straight line below it. You can set the value to this property using the setUnderline() method. It accepts a boolean value. You can have a line below the text (node) by passing true as an argument to this method.


1 Answers

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);
}
}   
like image 171
Aspirant Avatar answered Sep 25 '22 07:09

Aspirant