Wednesday, 4 November 2020

JavaFX: Glow effect

Glow is a high-level effect that makes the input image appear to glow, based on a configurable threshold.

 

Glow class provides following constructors to get an instance of Glow.

 

public Glow()

public Glow(double level)

'level' specifies the level value, which controls the intensity of the glow effect. Level is in range of 0 to 1, default value is 0.3. Value 0 specifies, no pixels glow, value 1 specifies all pixels should glow.

 

Example

	<Text fx:id = "text1" text="JavaFX"
	style="-fx-font-weight: bold; -fx-font-size: 50; -fx-font-family: Verdana; -fx-font-style: italic"
	stroke="darkblue" strokeWidth="2" 
	underline="true"
	fill="yellow"
	effect="$glowEffect1">
	
		<Glow fx:id="glowEffect1" level="1.0f" />
	</Text>

 

Find the below working application.

 

glowEffect.fxml

 

<?import javafx.scene.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.effect.*?>

<StackPane xmlns:fx="http://javafx.com/fxml" fx:controller="com.sample.app.effects.controller.GlowEffectController">

	<Rectangle fx:id="rectangle1" arcHeight="30" arcWidth="30" fill="green"
		width="300" height="50" smooth="true" stroke="black" strokeWidth="5" />
	
	<Text fx:id = "text1" text="JavaFX"
	style="-fx-font-weight: bold; -fx-font-size: 50; -fx-font-family: Verdana; -fx-font-style: italic"
	stroke="darkblue" strokeWidth="2" 
	underline="true"
	fill="yellow"
	effect="$glowEffect1">
	
		<Glow fx:id="glowEffect1" level="1.0f" />
	</Text>

</StackPane>

 

GlowEffectController.java

package com.sample.app.effects.controller;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;

public class GlowEffectController implements Initializable {

	@FXML
	private Rectangle rectangle1;

	@FXML
	private Text text1;

	@Override
	public void initialize(URL location, ResourceBundle resources) {

	
	}

}

 

GlowEffectDemo.java

package com.sample.app.effects;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class GlowEffectDemo extends Application {

	private static final String FXML_FILE = "/glowEffect.fxml";
	private static final String STAGE_TITLE = "Glow Effect";

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

	}

	@Override
	public void start(Stage primaryStage) throws Exception {

		Parent root = (Parent) FXMLLoader.load(this.getClass().getResource(FXML_FILE));

		Scene scene = new Scene(root, 600, 400, Color.LIGHTGRAY);

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

}

 

Output



 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment