how to change label text color javafx

how to change label text color javafx

To change the text color of a label in JavaFX, you can use the setTextFill method of the Label class and pass it a Color object.

Here's an example of how you might do this:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        Label label = new Label("Hello, World!");
        label.setTextFill(Color.RED);

        StackPane root = new StackPane();
        root.getChildren().add(label);

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
Sou‮l.www:ecr‬autturi.com

In this example, the setTextFill method is used to set the text color of the Label to red. The color is specified using the Color class.

You can use any valid color code to set the text color of the label as desired.

Created Time:2017-11-01 12:05:13  Author:lautturi