How To Make Text Double Underline in JavaFX?

Overview

In this tutorial, we show you how to make text double underline in Label JavaFX.
Text Double Underline in JavaFX



Text Double Underline using JavaFX Scene Builder 2.0

If you are using JavaFX Scene Builder 2.0, go to the Style of the TextField in the Properties section of the Inspector panel. Add Css Style:
-fx-border-color: black, transparent, black
-fx-border-width: 0 0 1 0, 0 0 1 0, 0 0 1 0
-fx-border-insets: 0 0 1 0, 0 0 2 0, 0 0 3 0
JavaFX Scene Builder 2.0

Text Double Underline by edit *.fxml file

Edit Example.fxml file, then Add CSS Style style="-fx-border-color: black, transparent, black; -fx-border-width: 0 0 1 0, 0 0 1 0, 0 0 1 0; -fx-border-insets: 0 0 1 0, 0 0 2 0, 0 0 3 0;" to Label tag.
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" fx:id="main" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: #FFFACD;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.jackrutorial.ExampleController">
   <children>
      <Label fx:id="txtDescription" alignment="CENTER" layoutX="220.0" layoutY="180.0" prefHeight="30.0" prefWidth="160.0" style="-fx-border-color: black, transparent, black; -fx-border-width: 0 0 1 0, 0 0 1 0, 0 0 1 0; -fx-border-insets: 0 0 1 0, 0 0 2 0, 0 0 3 0;" text="Text Double Underline" />
   </children>
</AnchorPane>

Text Double Underline using javafx.scene.control.Label.setStyle

Using method javafx.scene.control.Label.setStyle
    @FXML
    private Label txtDescription;

    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {

        txtDescription.setStyle("-fx-border-color: black, transparent, black; -fx-border-width: 0 0 1 0, 0 0 1 0, 0 0 1 0; -fx-border-insets: 0 0 1 0, 0 0 2 0, 0 0 3 0");
    }

Full SourceCode

ExampleController.java

package com.jackrutorial;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;

public class ExampleController implements Initializable {

    @FXML
    private Label txtDescription;

    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {

        txtDescription.setStyle("-fx-border-color: black, transparent, black; -fx-border-width: 0 0 1 0, 0 0 1 0, 0 0 1 0; -fx-border-insets: 0 0 1 0, 0 0 2 0, 0 0 3 0");
    }
}

Example.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" fx:id="main" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: #FFFACD;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.jackrutorial.ExampleController">
   <children>
      <Label fx:id="txtDescription" alignment="CENTER" layoutX="220.0" layoutY="180.0" prefHeight="30.0" prefWidth="160.0" text="Text Double Underline" />
   </children>
</AnchorPane>
Text Double Underline in JavaFX Label
Demo Text Double Underline in JavaFX Label

Previous Post
Next Post

post written by: