/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package scrollpanetransform_11253; import javafx.application.Application; import javafx.beans.InvalidationListener; import javafx.beans.Observable; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.geometry.Orientation; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.ScrollPane; import javafx.scene.control.Slider; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.transform.Scale; /** * @author mickf */ public class Main extends Application { private static final String URL_PREFIX = "file:src/scrollpanetransform_11253/"; public static Image createImage(String filename, float width, float height) { return new Image(URL_PREFIX + filename, width, height, true, true, false); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(Main.class, args); } final ScrollPane sView1 = new ScrollPane(); final Slider scaleSlider = new Slider(0.0, 2.0, 1.0); final Scale scaleTransform = new Scale(); private Group scaledGroup; private Group containerGroup; private final InvalidationListener containerGroupListener = new InvalidationListener() { @Override public void invalidated(Observable valueModel) { sView1.setVmax(containerGroup.prefWidth(-1)); sView1.setHmax(containerGroup.prefHeight(-1)); } }; @Override public void start(Stage stage) { Image image1 = createImage("duke.jpg", 200f, 200f); ImageView imageView1 = new ImageView(); imageView1.setImage(image1); stage.setTitle("ScrollPane Transform"); stage.setWidth(320); stage.setHeight(400); Scene scene = new Scene(new Group()); scene.setFill(Color.CHOCOLATE); Group root = (Group)scene.getRoot(); scaleSlider.setOrientation(Orientation.HORIZONTAL); scaleSlider.setLayoutX(50); scaleSlider.setLayoutY(280); scaleSlider.setValue(1.0); scaleSlider.setMajorTickUnit(0.25); scaleSlider.setMinorTickCount(5); scaleSlider.setShowTickLabels(true); scaleSlider.setShowTickMarks(true); ChangeListener scaleListener = new ChangeListener() { public void changed(ObservableValue ov, Object old_val, Object new_val) { scaleTransform.setX(scaleSlider.getValue()); scaleTransform.setY(scaleSlider.getValue()); } }; scaleSlider.valueProperty().addListener(scaleListener); root.getChildren().add(scaleSlider); scaleTransform.setX(scaleSlider.getValue()); scaleTransform.setY(scaleSlider.getValue()); scaledGroup = new Group(); scaledGroup.getChildren().clear(); scaledGroup.getChildren().addAll(imageView1); scaledGroup.getTransforms().addAll(scaleTransform); containerGroup = new Group(); containerGroup.getChildren().addAll(scaledGroup); containerGroup.layoutBoundsProperty().addListener(containerGroupListener); sView1.setPrefSize(120, 120); sView1.setContent(containerGroup); sView1.setPannable(true); sView1.setLayoutX(10); sView1.setLayoutY(5); root.getChildren().add(sView1); stage.setScene(scene); stage.setVisible(true); } }