Apply bloom effect using JavaFx 2.0


In following program you get an idea how to apply bloom effect for our created GUI object in JavaFx2.1 .

// Comment 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javafxblendingmode;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.effect.BlendMode;
import javafx.scene.effect.Bloom;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

/**
 *
 * @author allinalljava.blogspot.com
 */
public class JavaFXBloomEffect extends Application {

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

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Bloom Effect");
        Bloom bloom =new Bloom();
        bloom.setThreshold(0.5);      

Text t = new Text();
t.setText("Bloom!");
t.setFill(Color.YELLOW);
t.setFont(Font.font("null", FontWeight.BOLD, 36));
t.setX(25);
t.setY(65);
Circle c = new Circle();
c.setFill(Color.BLACK);
c.setCenterX(590);
c.setCenterY(50);
c.setRadius(70);

        StackPane root = new StackPane();

        root.setEffect(bloom);
         root.getChildren().add(c);
       root.getChildren().add(t);

        primaryStage.setScene(new Scene(root, 300, 250,Color.CADETBLUE));
        primaryStage.show();
    }
}



Output

raja P Web Developer

1 comment:

Related Posts Plugin for WordPress, Blogger...