Tuesday, January 31, 2012

JavaFX exercise: Set text color using javafx.scene.paint.Color

Set text color using javafx.scene.paint.Color
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javafx_extext;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;

/**
*
* @author erix7
*/
public class JavaFX_exText extends Application {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("java-buddy.blogspot.com");
Group root = new Group();
Scene scene = new Scene(root, 400, 300, Color.WHITE);

Text text = new Text(50, 50, "Hello Java-Buddy");
int red = 255;
int green = 0;
int blue = 0;
text.setFill(Color.rgb(red, green, blue, 0.9));

Text text2 = new Text(50, 100, "Hello Java-Buddy");
text2.setFill(Color.GREEN);
Text text3 = new Text(50, 150, "Hello Java-Buddy");
text3.setFill(Color.hsb(40, 0.7, 0.8));

root.getChildren().add(text);
root.getChildren().add(text2);
root.getChildren().add(text3);

primaryStage.setScene(scene);
primaryStage.show();
}
}

1 comment:

  1. How do change the font weight and colour of Label.Please help.

    ReplyDelete