
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to adjust the line spacing in the text node in JavaFX?
The line spacing property of the javafx.scene.text.The text class specifies the line spacing between the lines of the text (node) vertically.
You can set the value to this property using the setLineSpacing() method. This method accepts a boolean value as a parameter and sets the specified space between the lines (vertically).
Example
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Scanner; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; public class TextSpacing 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 alignment text.setTextAlignment(TextAlignment.JUSTIFY); //Setting the space text.setLineSpacing(2.0); //Setting the stage Group root = new Group(text); Scene scene = new Scene(root, 595, 150, Color.BEIGE); stage.setTitle("Line Spacing (2.0)"); 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, the following will be the output if you set the line spacing as 8.0 −
- Related Articles
- How to adjust the alignments of the text in JavaFX?
- How to create text node in JavaFX?
- How to set font to text node in JavaFX?
- How to add a blur effect to a text node in JavaFX?
- How to add a reflection effect to a text node in JavaFX?
- How to add a drop shadow effect to a text node in JavaFX?
- How to add an inner shadow effect to a text node in JavaFX?
- How to wrap the text in text flow layout in JavaFX?
- How to rotate a node in JavaFX?
- How to set the spacing between words in a text in JavaScript?
- How to adjust the contrast of an image using contrast() function in Node Jimp?
- How to Create the path element line in JavaFX?
- How to wrap the text of a label in JavaFX?
- How to Create the path element horizontal line in JavaFX?
- How to Create the path element vertical line in JavaFX?

Advertisements