/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ package binding; import javafx.application.Application; import javafx.beans.property.DoubleProperty; import javafx.builders.VBoxBuilder; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Slider; import javafx.scene.layout.VBox; import javafx.scene.text.Text; import javafx.stage.Stage; /** * * @author Sergey Grinev */ public class BindingText extends Application { private static final String txt = "ABCDEFGHIJK WWW"; @Override public void start(Stage stage) { Text text = new Text(txt); Slider slider = new Slider(0, 5, 1); slider.setPrefWidth(400); slider.setMajorTickUnit(0.5); slider.setShowTickLabels(true); slider.setShowTickMarks(true); text.scaleXProperty().bind(slider.valueProperty()); VBox vbox = new VBoxBuilder().children(text, slider).alignment(Pos.CENTER).spacing(10).build(); stage.setScene(new Scene(vbox)); stage.setWidth(500); stage.setHeight(500); stage.setVisible(true); for (double d : new double[]{0.2, 0.5, 1., 1.5, 2., 3.}) { Text t = new Text(txt + d); Text t2 = new Text(txt + d); vbox.getChildren().addAll(t, t2); t.setScaleX(d); DoubleProperty dp = new DoubleProperty(d); t2.scaleXProperty().bind(dp); } } public static void main(String[] args) { launch(args); } }