JavaFX Glow effect

Description

JavaFX Glow effect

  
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.effect.Glow;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage; 
  
public class Main extends Application {  
  
  double glowVal = 0.0; 
 
  Glow glow = new Glow(0.0); 
 
  // Create four push buttons.  
  Button btn = new Button("Click to see effect");  
 
  public static void main(String[] args) {  
    launch(args);    //www.j av a  2s.  co m
  }  
  public void start(Stage myStage) {  
    myStage.setTitle("Effects Demo");  
    FlowPane rootNode = new FlowPane(10, 10);  
    rootNode.setAlignment(Pos.CENTER);  
    Scene myScene = new Scene(rootNode, 300, 100);  
    myStage.setScene(myScene);  
    btn.setEffect(glow);    
 
  
    btn.setOnAction(new EventHandler<ActionEvent>() {  
      public void handle(ActionEvent ae) {  
        // Each time button is pressed, its glow value is changed. 
        glowVal += 0.1; 
        if(glowVal > 1.0) glowVal = 0.0; 
 
        // Set the new glow value. 
        glow.setLevel(glowVal); 
      }  
    });  
 
    // Add the label and buttons to the scene graph.  
    rootNode.getChildren().addAll(btn);  
 
    // Show the stage and its scene.  
    myStage.show();  
  }  
}



PreviousNext

Related