- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is text origin in JavaFX?
In addition to the local coordinate system for positioning its nodes, JavaFX provides an additional coordinate system for the text node.
The textOrigin property specifies the origin of the coordinates of the text node in the parent coordinate system. You can set values to this property using the setTextOrigin() method. This method accepts one of the constants of the enum named VPos. This enum contains 4 constants namely: BASELINE, BOTTOM, CENTER and, TOP.
Example
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Scanner; import javafx.application.Application; import javafx.geometry.VPos; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.text.Text; public class TextOriginExample extends Application { public void start(Stage stage) throws FileNotFoundException { //Reading the contents of a text file. InputStream inputStream = new FileInputStream("D:\sample_text.txt"); Scanner sc = new Scanner(inputStream); StringBuffer sb = new StringBuffer(); while(sc.hasNext()) { sb.append(" "+sc.nextLine()+"\n"); } //Creating a text object Text text = new Text(10.0, 25.0, sb.toString()); //Wrapping the text text.setWrappingWidth(565); //Setting the vertical positioning text.setTextOrigin(VPos.TOP); //Setting the stage Group root = new Group(text); Scene scene = new Scene(root, 595, 150, Color.BEIGE); stage.setTitle("Text Origin (TOP)"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
sample.txt
Assume following are the contents of the sample.txt file −
Tutorials Point originated from the idea that there exists a class of readers who respond better to online content and prefer to learn new skills at their own pace from the comforts of their drawing rooms. The journey commenced with a single tutorial on HTML in 2006 and elated by the response it generated, we worked our way to adding fresh tutorials to our repository which now proudly flaunts a wealth of tutorials and allied articles on topics ranging from programming languages to web designing to academics and much more.
Output
In the same way, if you change the alignment value you will get the outputs accordingly as −
BASELINE −
BOTTOM −
CENTER −
- Related Articles
- How to wrap the text in text flow layout in JavaFX?
- How to create text node in JavaFX?
- How to create a text area in JavaFX?
- How to add various fonts to text using text flow in JavaFX?
- What is shear transform in JavaFX?
- What is scale transformation in JavaFX?
- How to set font to text node in JavaFX?
- How to strike through and underline text in JavaFX?
- How to create a text flow layout in JavaFX?
- How to create a text field using JavaFX?
- How to add stroke and color to text in JavaFX?
- How to adjust the alignments of the text in JavaFX?
- How to add custom fonts to a text in JavaFX?
- How to make a text bold and italic in JavaFX?
- How to wrap the text of a label in JavaFX?

Advertisements