import java.io.IOException; import javafx.animation.Animation; import javafx.animation.TranslateTransition; import javafx.application.Application; import javafx.application.Platform; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.effect.DropShadow; import javafx.scene.effect.GaussianBlur; import javafx.scene.effect.Glow; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.scene.text.Text; import javafx.stage.Stage; import javafx.util.Duration; public class NeonText extends Application{ public static void main(String[] args) throws IOException { launch(args); } @Override public void start(Stage stage) throws Exception { Circle circle = new Circle(80); circle.setId("circle1"); circle.setFill(Color.RED); Circle circle2 = new Circle(100); circle2.setId("circle2"); StackPane pane = new StackPane(circle, text(), circle2); pane.setAlignment(Pos.CENTER); Scene scene = new Scene(pane); stage.setScene(scene); stage.setWidth(500); stage.setHeight(500); scene.getStylesheets().add("styles.css"); stage.show(); } private Text text() { Text text = new Text(" LOADING "); GaussianBlur gb = new GaussianBlur(5); DropShadow dropShadow = new DropShadow(15, Color.WHITE); gb.setInput(dropShadow); Glow glow = new Glow(); glow.setInput(gb); text.setEffect(glow); text.setId("text"); TranslateTransition transition = new TranslateTransition(Duration.seconds(2), text); transition.setByX(-2); transition.setCycleCount(Animation.INDEFINITE); transition.setFromX(100); transition.setToX(-100); Platform.runLater(transition::playFromStart); return text; } }
styled using hilite.me