Results 1 to 1 of 1
  1. #1
    paulhr is offline Member
    Join Date
    Aug 2015
    Posts
    1
    Rep Power
    0

    Default Need help with some ScrollPane() features

    Need help with some ScrollPane() features

    I have a group of geometric shapes, spheres, circles, lines, paths, etc... Because the unit of measure for the problem domain is large I have to scale the group. So for example I have a circle with a radius of 10,000 and a line that is 100,000 long. I want to keep the numbers for the geometric shape in the same unit of measure as the problem domain and not have to calculate scale with every change, so I scale the group and not each node in the group.

    I have been reading forums and playing around with no results. The code below is missing the following...

    1) I want the scrolls H/V to only work when click & dragged with the mouse.
    2) I want the mouse wheel scroll to zoom in/out
    3) I want the circle to start rendered in the center of the stage/scene/pane with all nodes within the border. Being a newbie it not clear to me which object would be responsible.

    Is someone willing to help point me in the correct direction?

    Java FX Code:
    package software;
    
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.geometry.Point2D;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.ScrollPane;
    import javafx.scene.input.ScrollEvent;
    import javafx.scene.layout.VBox;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Circle;
    import javafx.stage.Stage;
    
    public class SandBox extends Application  {
    
        final ScrollPane sp = new ScrollPane();
    
        public SandBox() {
    		// TODO Auto-generated constructor stub
    	}
    
    	public static void main(String[] args) {
    	    launch(args);
    	}
    
    	@Override
    	// Modified from the below link
    	// http://docs.oracle.com/javafx/2/ui_controls/scrollpane.htm
    	public void start(Stage stage) throws Exception {
    	    final double SCALE_DELTA = 1.1;
    
    		VBox vbox = new VBox();
    		Scene scene = new Scene(vbox, 1200, 300);
    		stage.setScene(scene);
    		stage.setTitle("Ether Column");
    		Group group = new Group();
    		Circle circle = new Circle(100, 150, 1000, Color.GREEN);
    		group.getChildren().add(circle);
    		group.setScaleY(0.1);
    		group.setScaleX(0.1);
    		// This page says for a "Group" Union of all visible childrens' 
    		// visual bounds (boundsInParent) Does NOT include effect, clip, or transforms set directly on group,
    		// https://docs.oracle.com/javafx/2/api/javafx/scene/layout/package-summary.html
    		sp.setContent(group);
    		sp.setPannable(true);
    	    sp.setOnScroll(new EventHandler<ScrollEvent>() {
    		      @Override
    		      public void handle(ScrollEvent event) {
    		        event.consume();
    
    		        if (event.getDeltaY() == 0) {
    		          return;
    		        }
    
    		        double scaleFactor = (event.getDeltaY() > 0) ? SCALE_DELTA
    		            : 1 / SCALE_DELTA;
    		        System.out.println("scaleFactor: " + scaleFactor);
    		      }
    		    });
    		
    		// sp.setPrefViewportHeight(stage.getHeight());
    		// sp.setPrefViewportWidth(stage.getWidth());
    		vbox.getChildren().addAll(sp);
    		stage.show();
    		
    	}
    
    }
    Last edited by paulhr; 08-20-2015 at 08:01 PM.

Similar Threads

  1. How to scale the scrollpane's Vvalue
    By Jacques_ZA in forum New To Java
    Replies: 1
    Last Post: 01-25-2013, 01:45 PM
  2. forcing scrollpane to autoscroll
    By yemista in forum AWT / Swing
    Replies: 6
    Last Post: 05-26-2012, 07:59 PM
  3. how to add a scrollpane to Jframe
    By yaminisankar in forum AWT / Swing
    Replies: 1
    Last Post: 07-09-2009, 09:56 AM
  4. ScrollPane Issues..
    By hanifa in forum AWT / Swing
    Replies: 4
    Last Post: 09-11-2008, 08:18 AM
  5. scrollpane
    By Newb in forum AWT / Swing
    Replies: 0
    Last Post: 06-09-2008, 12:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •