Tuesday, January 31, 2012

JavaFX exercise: add shadow effect on text

shadow effect on text
/*
* 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.effect.DropShadow;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
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);

DropShadow shadow = new DropShadow();
shadow.setOffsetX(5.0);
shadow.setOffsetY(5.0);
shadow.setColor(Color.BLACK);

Text text = new Text(50, 50, "Serif");
text.setFill(Color.RED);
text.setFont(Font.font("Serif", 20));
text.setEffect(shadow);

Text text2 = new Text(50, 100, "SanSerif");
text2.setFill(Color.GREEN);
text2.setFont(Font.font("SanSerif", 30));
text2.setEffect(shadow);

Text text3 = new Text(50, 150, "Monospaced");
text3.setFill(Color.BLUE);
text3.setFont(Font.font("Monospaced", 40));
text3.setEffect(shadow);

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

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

No comments:

Post a Comment