TextAlignment class is a part of JavaFX. The TextAlignment class represents the horizontal text alignment. TextAlignment class inherits Enum class.
Commonly Used Methods:
|valueOf(String n)||Returns the text Alignment of specified name.|
|values()||Returns an array which contains all the values of text alignment.|
Example: Java program to create a TextFlow and add text object to it, set text Alignment and also set a combo box to change Alignment and set line spacing of the text flow: In this program we will create a TilePane named tile_pane. Add Label named label and some buttons to the tile_pane. Set the Alignment of the tile_pane using the setAlignment() function. Store all the names of TextAlignment values in a String array. Now create an combobox which will contain the names of TextAlignment values and also create an Action Event to handle the combobox events. The Event handler will set the TextAlignment of the TextFlow to the chosen TextAlignment value. Now create a VBox and add the tilepane and the combo box to vbox. Finally, add the vbox to the scene and add the scene to the stage and call the show() function to display the final results.
Note: The above programs might not run in an online IDE please use an offline compiler.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.