/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. */ package helloworld; import javafx.application.Application; import javafx.application.Launcher; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.LayoutInfo; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.beans.Bean; import javafx.beans.event.ChangeListener; import javafx.beans.PropertyReference; import javafx.scene.transform.Scale; /** * @author mickf */ public class HelloScrollPaneScaleImage extends Application { private static final String URL_PREFIX = "file:src/helloworld/"; public static Image createImage(String filename, float width, float height) { return new Image(URL_PREFIX + filename, width, height, true, true, false, null); } /** * @param args the command line arguments */ public static void main(String[] args) { Launcher.launch(HelloScrollPaneScaleImage.class, args); } final ScrollPane sView1 = new ScrollPane(); final Slider scaleSlider = new Slider(0.0, 2.0, 1.0); final CheckBox disCB = new CheckBox(); final CheckBox btnCB = new CheckBox(); final Scale scaleTransform = new Scale(); private Group scaledGroup; @Override public void start() { Image image1 = createImage("duke.jpg", 200f, 200f); ImageView imageView1 = new ImageView(); imageView1.setImage(image1); Stage stage = new Stage(); stage.setTitle("HelloScrollPaneScale"); stage.setWidth(320); stage.setHeight(400); Scene scene = new Scene(new Group()); scene.setFill(Color.CHOCOLATE); Group root = (Group)scene.getRoot(); scaleSlider.setVertical(false); 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() { @Override public void handle(Bean bean, PropertyReference pr) { scaleTransform.setX(scaleSlider.getValue()); scaleTransform.setY(scaleSlider.getValue()); } }; scaleSlider.addChangeListener(Slider.VALUE, 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); sView1.setLayoutInfo(new LayoutInfo(120, 120)); sView1.setNode(scaledGroup); sView1.setPannable(true); sView1.setLayoutX(10); sView1.setLayoutY(5); sView1.setBlocksMouse(false); root.getChildren().add(sView1); stage.setScene(scene); stage.setVisible(true); } }