JavaFX | FontPosture Class

FontPosture class is a part of JavaFX. FontPosture class specifies whether a font is REGULAR or ITALIC. FontPosture class inherits Enum class.

Commonly Used Methods:

Method Explanation
findByName(String n) Returns FontPosture by its name.
valueOf(String n) Returns a FontPosture with the specified name.
values() returns an array with all the elements of the FontPosture type.

Java Program to create a font object and set a specified posture and apply it to a text: In this program we will create two Text object and set one’s font posture to REGULAR and the other one to ITALIC. Then set the text to the TextFlow and add this textflow to the VBox and add the vbox to the scene, and add the scene to the stage. Also, set the line spacing and text alignment of the textflow and the spacing of the vbox. Call the show() function to display the final results.





// Java Program to create a font object and set
// a specified posture and  apply it to a text
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.scene.text.*;
import javafx.geometry.*;
import javafx.scene.layout.*;
import javafx.scene.shape.*;
public class FontPosture_1 extends Application {
    // launch the application
    public void start(Stage stage)
        try {
            // set title for the stage
            // create TextFlow
            TextFlow text_flow = new TextFlow();
            // create text
            Text text_1 = new Text("GeeksforGeeks\n");
            // set the text color
            // create a font
            Font font = Font.font("Verdana", FontWeight.EXTRA_BOLD,
                                          FontPosture.REGULAR, 25);
            // set font of the text
            // create text
            Text text_2 = new Text("A Computer Science portal for geeks\n");
            // set the text color
            // create a font
            Font font1 = Font.font("Verdana", FontWeight.EXTRA_BOLD,
                                            FontPosture.ITALIC, 12);
            // set font of the text
            // set text
            // set line spacing
            // set text alignment
            // create VBox
            VBox vbox = new VBox(text_flow);
            // set alignment of vbox
            // create a scene
            Scene scene = new Scene(vbox, 400, 300);
            // set the scene
        catch (Exception e) {
    // Main Method
    public static void main(String args[])
        // launch the application



Note: The above programs might not run in an online IDE please use an offline compiler.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.