
- 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 strike through and underline text in JavaFX?
In JavaFX, the text node is represented by the Javafx.scene.text.Text class. To insert/display text in JavaFx window you need to −
Instantiate the Text class.
Set the basic properties like position and text string, using the setter methods or, bypassing them as arguments to the constructor.
Add the created node to the Group object.
The strikethrough property of the javafx.scene.text.Text class determines whether each line of the text should have a straight line passing through the middle of it. You can set the value to this property using the setStrikeThrough() method. It accepts a boolean value. You can strike though the text (node) by passing true as an argument to this method.
The underline property of the javafx.scene.text.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.
Example
import java.io.FileNotFoundException; 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.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; public class Underline_StrikeThrough extends Application { public void start(Stage stage) throws FileNotFoundException { //Creating a text object String str = "Welcome to Tutorialspoint"; Text text = new Text(30.0, 80.0, str); //Setting the font Font font = Font.font("Brush Script MT", FontWeight.BOLD, FontPosture.REGULAR, 65); text.setFont(font); //Setting the color of the text text.setFill(Color.DARKCYAN); //Setting the width and color of the stroke text.setStrokeWidth(2); text.setStroke(Color.DARKSLATEGRAY); //Underlining the text text.setUnderline(true); //Striking through the text text.setStrikethrough(true); //Setting the stage Group root = new Group(text); Scene scene = new Scene(root, 595, 150, Color.BEIGE); stage.setTitle("Underline And Strike-through"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
Output
- Related Articles
- How to underline a text in HTML?
- How to add underline to Text using FabricJS?
- How to make text bold, italic and underline using jQuery
- Underline text with CSS
- How to remove underline from text hyperlink using jQuery?
- Underline Text in Tkinter Label widget
- How to add stroke and color to text in JavaFX?
- How to create text node in JavaFX?
- How to make a text bold and italic in JavaFX?
- How to wrap the text in text flow layout in JavaFX?
- How to Change Link Underline Color using text-decoration-color CSS
- How to create a text area in JavaFX?
- How to add various fonts to text using text flow in JavaFX?
- How to set font to text node in JavaFX?
- How to create a text flow layout in JavaFX?
