Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8940265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:59:48+00:00 2026-06-15T10:59:48+00:00

I am trying to make a group which contains Rectangle and Text objects to

  • 0

I am trying to make a group which contains Rectangle and Text objects to scale up and down using the ScrollEvent. I am having trouble getting the correct scale to use from the delta of the scroll. The following code is what I have at the moment. Any help will be appreciated.

Thanks

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.ScrollEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.stage.Stage;

// demonstrates scaling a test pane with content in it.
public class ScaleTest extends Application {
    Group page;
    double textScale =1.0;
    public static void main(String[] args) {
        launch();
    }

    @Override
    public void start(Stage stage) throws Exception {
        stage.setTitle("scale test");
        Group root = new Group();
        page= new Group();
        Rectangle r = new Rectangle(300,300);
        Text t = new Text("asodjoijdjiasjdoijaisjdijasijdiajsidjoiasjiodjiajosijdiojaisjdoijaoisjdiojaoisjdjaoisjdiojsoidj\njdoasijdoajsoidjoaisjoidjaoisjdiojs");
        t.setFill(Color.FLORALWHITE);
        t.setWrappingWidth(280);
        t.setX(10);
        t.setY(20);
        page.getChildren().addAll(r,t);
        root.getChildren().add(page);
        Scene scene = new Scene(root,800,600);
        this.setSceneEvents(scene);
        stage.setScene(scene);
        stage.show();
    }
    private void setSceneEvents(final Scene scene) {
        //handles mouse scrolling
        scene.setOnScroll(
                new EventHandler<ScrollEvent>() {
                    @Override
                    public void handle(ScrollEvent event) {
                        double xscale = page.getScaleX() * event.getDeltaY()/35;
                        double yscale= page.getScaleY() * event.getDeltaY()/35;
                        System.out.println("xscale: "+ xscale);
                        System.out.println("yscale: "+ yscale);
                        //page.setScaleX(page.getScaleX() * event.getDeltaY()/35);
                       // page.setScaleY(page.getScaleY() * event.getDeltaY()/35);
                        event.consume();
                    }
                });

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:59:50+00:00Added an answer on June 15, 2026 at 10:59 am

    |deltaY| is for all scroll events the same. Also note that deltaY is negative for scrolling down, and the scaling always is normalized at 1.0. So i suggest to use a “zoom factor” which determines the scaling. Try something like:

    private void setSceneEvents(final Scene scene) {
        //handles mouse scrolling
        scene.setOnScroll(
                new EventHandler<ScrollEvent>() {
                  @Override
                  public void handle(ScrollEvent event) {
                    double zoomFactor = 1.05;
                    double deltaY = event.getDeltaY();
                    if (deltaY < 0){
                      zoomFactor = 2.0 - zoomFactor;
                    }
                    System.out.println(zoomFactor);
                    page.setScaleX(page.getScaleX() * zoomFactor);
                    page.setScaleY(page.getScaleY() * zoomFactor);
                    event.consume();
                  }
                });
    
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am trying to make a drop down list for a group of
UPDATE I am trying to add a group which include textboxes and simple text
I am trying to make a group activity with the radio widget. My problem
I'm trying to make a case against automated checkins to version control. My group
I am fairly new to iOS development and trying make a simple app which
I'm trying to make a radio group specifying a bunch of options, and an
I'm trying to group (or at least make unique) a column m_group_name unless the
I am using knockout.js and knockout.validation plugin. I have a search form which contains
I'm trying to group my documents but I don't understand how to make a
I'm trying to make a tab bar in android using a RelativeLayout and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.