JavaFX Label set text fill color

Description

JavaFX Label set text fill color

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Main extends Application {
  @Override//from ww w  .  ja v a2s  . c  om
  public void start(Stage primaryStage) {
    FlowPane pane = new FlowPane();
    pane.setAlignment(Pos.CENTER);
    // Crate a Text and set its properties
    Label text = new Label("Java");
    text.setTextFill(new Color(Math.random(), Math.random(), 
        Math.random(), Math.random()));
        
    pane.getChildren().add(text);
    Scene scene = new Scene(pane, 150, 150);
    primaryStage.setTitle("java2s.com");
    primaryStage.setScene(scene);
    primaryStage.show();
  }

  public static void main(String[] args) {
    Application.launch(args);
  }
}



PreviousNext

Related