JavaFX: Applying Effects To Label

We have looked at Label and we have made use of lambda function to call the event, we can now set up a mouse over effect on a Label.

When the mouse move over the label, a scaling factor of 1.5 is applied to the Label. This is done by using the setScale method.

package javafxapplication15;

import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;

public class JavaFXApplication15 extends Application {

    @Override
    public void start(Stage stage) {

        Label lb = new Label("Every Picture Tells A Story");

        lb.setOnMouseEntered((MouseEvent e) -> {
            lb.setScaleX(1.5);
            lb.setScaleY(1.5);
        });

        lb.setOnMouseExited(e -> {
            lb.setScaleX(1);
            lb.setScaleY(1);
        });

        BorderPane pane = new BorderPane();
        pane.setCenter(lb);
        Scene scene = new Scene(pane, 300, 250);
        stage.setScene(scene);
        stage.setTitle("JavaFX Program");
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }

}

scale1

 

Series Navigation<< JavaFX: Calling Event Using Lambda Expression
JavaFX: Applying Shadow Effect >>