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);
}
}Soul.www:ecrautturi.comIn 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.