JavaFX Scale effect

Description

JavaFX Scale 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.layout.FlowPane;
import javafx.scene.transform.Scale;
import javafx.stage.Stage; 
  
public class Main extends Application {  
  
   double scaleFactor = 1.0; 
   //from   w  w  w. j  ava2  s.  c  om
   Scale scale = new Scale(scaleFactor, scaleFactor); 
  // Create four push buttons.  
  private Button btn = new Button("Click to see effect");  
 
  public static void main(String[] args) {  
    launch(args);    
  }  
  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.getTransforms().add(scale);  
 
  
    btn.setOnAction(new EventHandler<ActionEvent>() {  
      public void handle(ActionEvent ae) {  
         // Each time button is pressed, the button's scale is changed. 
         scaleFactor += 0.1; 
         if(scaleFactor > 1.0) scaleFactor = 0.4; 
  
         scale.setX(scaleFactor); 
         scale.setY(scaleFactor);   
      }  
    });  
 
    // Add the label and buttons to the scene graph.  
    rootNode.getChildren().addAll(btn);  
 
    // Show the stage and its scene.  
    myStage.show();  
  }  
}



PreviousNext

Related