Zoomable JScrollPane - setViewPosition 无法更新

2023-12-29

我正在尝试编写一个可缩放图像在 JScrollPane 中。

当图像完全缩小时,它应该水平和垂直居中。当两个滚动条都出现时,缩放应始终相对于鼠标坐标进行,即在缩放事件之前和之后图像的同一点应位于鼠标下方。

我已经快要达到我的目标了。不幸的是,“scrollPane.getViewport().setViewPosition()”方法有时无法正确更新视图位置。在大多数情况下,调用该方法两次(hack!)可以解决该问题,但视图仍然闪烁。

我无法解释为什么会发生这种情况。但我确信这不是一个数学问题。


下面是 MWE。要查看我的问题具体是什么,您可以执行以下操作:

  • 放大直到出现一些滚动条(200% 左右缩放)
  • 单击滚动条滚动到右下角
  • 将鼠标放在角落并放大两倍。第二次您将看到滚动位置如何跳向中心。

如果有人能告诉我问题出在哪里,我将非常感激。谢谢你!

package com.vitco;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseWheelEvent;
import java.awt.image.BufferedImage;
import java.util.Random;

/**
 * Zoom-able scroll panel test case
 */
public class ZoomScrollPanel {

    // the size of our image
    private final static int IMAGE_SIZE = 600;

    // create an image to display
    private BufferedImage getImage() {
        BufferedImage image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        // draw the small pixel first
        Random rand = new Random();
        for (int x = 0; x < IMAGE_SIZE; x += 10) {
            for (int y = 0; y < IMAGE_SIZE; y += 10) {
                g.setColor(new Color(rand.nextInt(255),rand.nextInt(255),rand.nextInt(255)));
                g.fillRect(x, y, 10, 10);
            }
        }
        // draw the larger transparent pixel second
        for (int x = 0; x < IMAGE_SIZE; x += 100) {
            for (int y = 0; y < IMAGE_SIZE; y += 100) {
                g.setColor(new Color(rand.nextInt(255),rand.nextInt(255),rand.nextInt(255), 180));
                g.fillRect(x, y, 100, 100);
            }
        }
        return image;
    }

    // the image panel that resizes according to zoom level
    private class ImagePanel extends JPanel {
        private final BufferedImage image = getImage();

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g.create();
            g2.scale(scale, scale);
            g2.drawImage(image, 0, 0, null);
            g2.dispose();
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension((int)Math.round(IMAGE_SIZE * scale), (int)Math.round(IMAGE_SIZE * scale));
        }
    }

    // the current zoom level (100 means the image is shown in original size)
    private double zoom = 100;
    // the current scale (scale = zoom/100)
    private double scale = 1;

    // the last seen scale
    private double lastScale = 1;

    public void alignViewPort(Point mousePosition) {
        // if the scale didn't change there is nothing we should do
        if (scale != lastScale) {
            // compute the factor by that the image zoom has changed
            double scaleChange = scale / lastScale;

            // compute the scaled mouse position
            Point scaledMousePosition = new Point(
                    (int)Math.round(mousePosition.x * scaleChange),
                    (int)Math.round(mousePosition.y * scaleChange)
            );

            // retrieve the current viewport position
            Point viewportPosition = scrollPane.getViewport().getViewPosition();

            // compute the new viewport position
            Point newViewportPosition = new Point(
                    viewportPosition.x + scaledMousePosition.x - mousePosition.x,
                    viewportPosition.y + scaledMousePosition.y - mousePosition.y
            );

            // update the viewport position
            // IMPORTANT: This call doesn't always update the viewport position. If the call is made twice
            // it works correctly. However the screen still "flickers".
            scrollPane.getViewport().setViewPosition(newViewportPosition);

            // debug
            if (!newViewportPosition.equals(scrollPane.getViewport().getViewPosition())) {
                System.out.println("Error: " + newViewportPosition + " != " + scrollPane.getViewport().getViewPosition());
            }

            // remember the last scale
            lastScale = scale;
        }
    }

    // reference to the scroll pane container
    private final JScrollPane scrollPane;

    // constructor
    public ZoomScrollPanel() {
        // initialize the frame
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(600, 600);

        // initialize the components
        final ImagePanel imagePanel = new ImagePanel();
        final JPanel centerPanel = new JPanel();
        centerPanel.setLayout(new GridBagLayout());
        centerPanel.add(imagePanel);
        scrollPane = new JScrollPane(centerPanel);
        scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        frame.add(scrollPane);

        // add mouse wheel listener
        imagePanel.addMouseWheelListener(new MouseAdapter() {
            @Override
            public void mouseWheelMoved(MouseWheelEvent e) {
                super.mouseWheelMoved(e);
                // check the rotation of the mousewheel
                int rotation = e.getWheelRotation();
                boolean zoomed = false;
                if (rotation > 0) {
                    // only zoom out until no scrollbars are visible
                    if (scrollPane.getHeight() < imagePanel.getPreferredSize().getHeight() ||
                            scrollPane.getWidth() < imagePanel.getPreferredSize().getWidth()) {
                        zoom = zoom / 1.3;
                        zoomed = true;
                    }
                } else {
                    // zoom in until maximum zoom size is reached
                    double newCurrentZoom = zoom * 1.3;
                    if (newCurrentZoom < 1000) { // 1000 ~ 10 times zoom
                        zoom = newCurrentZoom;
                        zoomed = true;
                    }
                }
                // check if a zoom happened
                if (zoomed) {
                    // compute the scale
                    scale = (float) (zoom / 100f);

                    // align our viewport
                    alignViewPort(e.getPoint());

                    // invalidate and repaint to update components
                    imagePanel.revalidate();
                    scrollPane.repaint();
                }
            }
        });

        // display our frame
        frame.setVisible(true);
    }

    // the main method
    public static void main(String[] args) {
        new ZoomScrollPanel();
    }
}

注意:我也看过这里的问题JScrollPane setViewPosition 在“缩放”之后 https://stackoverflow.com/questions/2067511/jscrollpane-setviewposition-after-zoom但不幸的是问题和解决方案略有不同并且不适用。


Edit

我已经通过使用 hack 解决了这个问题,但是我仍然没有更接近于理解根本问题是什么。发生的情况是,当调用 setViewPosition 时,某些内部状态更改会触发对 setViewPosition 的其他调用。这些额外的调用只是偶尔发生。当我阻止它们时,一切都正常。

为了解决这个问题,我简单地引入了一个新的布尔变量“blocked = false;”并更换了线路

    scrollPane = new JScrollPane(centerPanel);

and

    scrollPane.getViewport().setViewPosition(newViewportPosition);

with

    scrollPane = new JScrollPane();

    scrollPane.setViewport(new JViewport() {
        private boolean inCall = false;
        @Override
        public void setViewPosition(Point pos) {
            if (!inCall || !blocked) {
                inCall = true;
                super.setViewPosition(pos);
                inCall = false;
            }
        }
    });

    scrollPane.getViewport().add(centerPanel);

and

     blocked = true;
     scrollPane.getViewport().setViewPosition(newViewportPosition);
     blocked = false;

如果有人能理解这一点,我仍然会非常感激!

为什么这个黑客有效?有没有更干净的方法来实现相同的功能?


这是完整的、功能齐全的代码。我仍然不明白为什么黑客是必要的,但至少它现在按预期工作:

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseWheelEvent;
import java.awt.image.BufferedImage;
import java.util.Random;

/**
 * Zoom-able scroll panel
 */
public class ZoomScrollPanel {

    // the size of our image
    private final static int IMAGE_SIZE = 600;

    // create an image to display
    private BufferedImage getImage() {
        BufferedImage image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        // draw the small pixel first
        Random rand = new Random();
        for (int x = 0; x < IMAGE_SIZE; x += 10) {
            for (int y = 0; y < IMAGE_SIZE; y += 10) {
                g.setColor(new Color(rand.nextInt(255),rand.nextInt(255),rand.nextInt(255)));
                g.fillRect(x, y, 10, 10);
            }
        }
        // draw the larger transparent pixel second
        for (int x = 0; x < IMAGE_SIZE; x += 100) {
            for (int y = 0; y < IMAGE_SIZE; y += 100) {
                g.setColor(new Color(rand.nextInt(255),rand.nextInt(255),rand.nextInt(255), 180));
                g.fillRect(x, y, 100, 100);
            }
        }
        return image;
    }

    // the image panel that resizes according to zoom level
    private class ImagePanel extends JPanel {
        private final BufferedImage image = getImage();

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g.create();
            g2.scale(scale, scale);
            g2.drawImage(image, 0, 0, null);
            g2.dispose();
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension((int)Math.round(IMAGE_SIZE * scale), (int)Math.round(IMAGE_SIZE * scale));
        }
    }

    // the current zoom level (100 means the image is shown in original size)
    private double zoom = 100;
    // the current scale (scale = zoom/100)
    private double scale = 1;

    // the last seen scale
    private double lastScale = 1;

    // true if currently executing setViewPosition
    private boolean blocked = false;

    public void alignViewPort(Point mousePosition) {
        // if the scale didn't change there is nothing we should do
        if (scale != lastScale) {
            // compute the factor by that the image zoom has changed
            double scaleChange = scale / lastScale;

            // compute the scaled mouse position
            Point scaledMousePosition = new Point(
                    (int)Math.round(mousePosition.x * scaleChange),
                    (int)Math.round(mousePosition.y * scaleChange)
            );

            // retrieve the current viewport position
            Point viewportPosition = scrollPane.getViewport().getViewPosition();

            // compute the new viewport position
            Point newViewportPosition = new Point(
                    viewportPosition.x + scaledMousePosition.x - mousePosition.x,
                    viewportPosition.y + scaledMousePosition.y - mousePosition.y
            );

            // update the viewport position
            blocked = true;
            scrollPane.getViewport().setViewPosition(newViewportPosition);
            blocked = false;

            // remember the last scale
            lastScale = scale;
        }
    }

    // reference to the scroll pane container
    private final JScrollPane scrollPane;

    // constructor
    public ZoomScrollPanel() {
        // initialize the frame
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(600, 600);

        // initialize the components
        final ImagePanel imagePanel = new ImagePanel();
        final JPanel centerPanel = new JPanel();
        centerPanel.setLayout(new GridBagLayout());
        centerPanel.add(imagePanel);
        scrollPane = new JScrollPane();

        scrollPane.setViewport(new JViewport() {
            private boolean inCall = false;
            @Override
            public void setViewPosition(Point pos) {
                if (!inCall || !blocked) {
                    inCall = true;
                    super.setViewPosition(pos);
                    inCall = false;
                }
            }
        });

        scrollPane.getViewport().add(centerPanel);
        scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        frame.add(scrollPane);

        // add mouse wheel listener
        imagePanel.addMouseWheelListener(new MouseAdapter() {
            @Override
            public void mouseWheelMoved(MouseWheelEvent e) {
                super.mouseWheelMoved(e);
                // check the rotation of the mousewheel
                int rotation = e.getWheelRotation();
                boolean zoomed = false;
                if (rotation > 0) {
                    // only zoom out until no scrollbars are visible
                    if (scrollPane.getHeight() < imagePanel.getPreferredSize().getHeight() ||
                            scrollPane.getWidth() < imagePanel.getPreferredSize().getWidth()) {
                        zoom = zoom / 1.3;
                        zoomed = true;
                    }
                } else {
                    // zoom in until maximum zoom size is reached
                    double newCurrentZoom = zoom * 1.3;
                    if (newCurrentZoom < 1000) { // 1000 ~ 10 times zoom
                        zoom = newCurrentZoom;
                        zoomed = true;
                    }
                }
                // check if a zoom happened
                if (zoomed) {
                    // compute the scale
                    scale = (float) (zoom / 100f);

                    // align our viewport
                    alignViewPort(e.getPoint());

                    // invalidate and repaint to update components
                    imagePanel.revalidate();
                    scrollPane.repaint();
                }
            }
        });

        // display our frame
        frame.setVisible(true);
    }

    // the main method
    public static void main(String[] args) {
        new ZoomScrollPanel();
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Zoomable JScrollPane - setViewPosition 无法更新 的相关文章

  • Java Swing:从 JOptionPane 获取文本值

    我想创建一个用于 POS 系统的新窗口 用户输入的是客户拥有的金额 并且窗口必须显示兑换金额 我是新来的JOptionPane功能 我一直在使用JAVAFX并且它是不同的 这是我的代码 public static void main Str
  • 如何使用 Java 和 Selenium WebDriver 在 C 目录中创建文件夹并需要将屏幕截图保存在该目录中?

    目前正在与硒网络驱动程序和代码Java 我有一种情况 我需要在 C 目录中创建一个文件夹 并在该文件夹中创建我通过 selenium Web 驱动程序代码拍摄的屏幕截图 它需要存储在带有时间戳的文件夹中 如果我每天按计划运行脚本 所有屏幕截
  • Spring Batch 多线程 - 如何使每个线程读取唯一的记录?

    这个问题在很多论坛上都被问过很多次了 但我没有看到适合我的答案 我正在尝试在我的 Spring Batch 实现中实现多线程步骤 有一个包含 100k 条记录的临时表 想要在 10 个线程中处理它 每个线程的提交间隔为 300 因此在任何时
  • 在画布上绘图

    我正在编写一个 Android 应用程序 它可以在视图的 onDraw 事件上直接绘制到画布上 我正在绘制一些涉及单独绘制每个像素的东西 为此我使用类似的东西 for int x 0 x lt xMax x for int y 0 y lt
  • 如何找到给定字符串的最长重复子串

    我是java新手 我被分配寻找字符串的最长子字符串 我在网上研究 似乎解决这个问题的好方法是实现后缀树 请告诉我如何做到这一点或者您是否有任何其他解决方案 请记住 这应该是在 Java 知识水平较低的情况下完成的 提前致谢 附 测试仪字符串
  • 制作一个交互式Windows服务

    我希望我的 Java 应用程序成为交互式 Windows 服务 用户登录时具有 GUI 的 Windows 服务 我搜索了这个 我发现这样做的方法是有两个程序 第一个是服务 第二个是 GUI 程序并使它们进行通信 服务将从 GUI 程序获取
  • JAXb、Hibernate 和 beans

    目前我正在开发一个使用 Spring Web 服务 hibernate 和 JAXb 的项目 1 我已经使用IDE hibernate代码生成 生成了hibernate bean 2 另外 我已经使用maven编译器生成了jaxb bean
  • 无法解析插件 Java Spring

    我正在使用 IntelliJ IDEA 并且我尝试通过 maven 安装依赖项 但它给了我这些错误 Cannot resolve plugin org apache maven plugins maven clean plugin 3 0
  • 禁止的软件包名称:java

    我尝试从数据库名称为 jaane 用户名 Hello 和密码 hello 获取数据 错误 java lang SecurityException Prohibited package name java at java lang Class
  • 如何将 pfx 文件转换为 jks,然后通过使用 wsdl 生成的类来使用它来签署传出的肥皂请求

    我正在寻找一个代码示例 该示例演示如何使用 PFX 证书通过 SSL 访问安全 Web 服务 我有证书及其密码 我首先使用下面提到的命令创建一个 KeyStore 实例 keytool importkeystore destkeystore
  • 为什么HashMap不能保证map的顺序随着时间的推移保持不变

    我在这里阅读有关 Hashmap 和 Hashtable 之间的区别 http javarevisited blogspot sg 2010 10 difference Between hashmap and html http javar
  • JRE 系统库 [WebSphere v6.1 JRE](未绑定)

    将项目导入 Eclipse 后 我的构建路径中出现以下错误 JRE System Library WebSphere v6 1 JRE unbound 谁知道怎么修它 右键单击项目 特性 gt Java 构建路径 gt 图书馆 gt JRE
  • 加密 JBoss 配置中的敏感信息

    JBoss 中的标准数据源配置要求数据库用户的用户名和密码位于 xxx ds xml 文件中 如果我将数据源定义为 c3p0 mbean 我会遇到同样的问题 是否有标准方法来加密用户和密码 保存密钥的好地方是什么 这当然也与 tomcat
  • Java Integer CompareTo() - 为什么使用比较与减法?

    我发现java lang Integer实施compareTo方法如下 public int compareTo Integer anotherInteger int thisVal this value int anotherVal an
  • 无法捆绑适用于 Mac 的 Java 应用程序 1.8

    我正在尝试将我的 Java 应用程序导出到 Mac 该应用程序基于编译器合规级别 1 7 我尝试了不同的方法来捆绑应用程序 1 日食 我可以用来在 Eclipse 上导出的最新 JVM 版本是 1 6 2 马文 看来Maven上也存在同样的
  • 如何从指定日期获取上周五的日期? [复制]

    这个问题在这里已经有答案了 如何找出上一个 上一个 星期五 或指定日期的任何其他日期的日期 public getDateOnDay Date date String dayName 我不会给出答案 先自己尝试一下 但是 也许这些提示可以帮助
  • 在mockito中使用when进行模拟ContextLoader.getCurrentWebApplicationContext()调用。我该怎么做?

    我试图在使用 mockito 时模拟 ContextLoader getCurrentWebApplicationContext 调用 但它无法模拟 here is my source code Mock org springframewo
  • JGit 检查分支是否已签出

    我正在使用 JGit 开发一个项目 我设法删除了一个分支 但我还想检查该分支是否已签出 我发现了一个变量CheckoutCommand但它是私有的 private boolean isCheckoutIndex return startCo
  • 将 List 转换为 JSON

    Hi guys 有人可以帮助我 如何将我的 HQL 查询结果转换为带有对象列表的 JSON 并通过休息服务获取它 这是我的服务方法 它返回查询结果列表 Override public List
  • 按日期对 RecyclerView 进行排序

    我正在尝试按日期对 RecyclerView 进行排序 但我尝试了太多的事情 我不知道现在该尝试什么 问题就出在这条线上适配器 notifyDataSetChanged 因为如果我不放 不会显示错误 但也不会更新 recyclerview

随机推荐

  • Google 通讯录 api (gdata) 同步低分辨率照片

    我正在使用 google 联系人 api gdata 在 google 联系人中设置联系人的照片 我正在使用 fiddler 我看到请求是根据Google 通讯录示例 https developers google com google a
  • Angular Spectator setInput 不适用于非字符串输入

    我已经成功地将我的项目转换为使用 Jest 代替 Karma Jasmine 并且我有很多测试运行得很好 我正在尝试使用 Spectator 5 2 1 进行一个非常简单的测试 但它不起作用 我正在尝试测试使用 mat table 呈现表格
  • Rails 路由的 API 版本控制

    我正在尝试像 Stripe 那样对我的 API 进行版本控制 下面给出的最新 API 版本是 2 api users返回 301 api v2 users api v1 users返回版本 1 的 200 个用户索引 api v3 user
  • 多条件IF语句

    我有一个包含多个条件的 if 语句 但我似乎无法正确执行 if ISSET SESSION status SESSION username qqqqq ISSET SESSION status SESSION company wwwwww
  • Kotlin 中通过反射获取 Enum 值

    您将如何用 Kotlin 重写以下 Java 代码 SuppressWarnings unchecked rawtypes static Object getEnumValue String enumClassName String enu
  • 如何将顶视图折叠成较小尺寸的视图?

    这个问题之前曾以过于宽泛和不清楚的方式提出过here https stackoverflow com q 47053822 878126 所以我使它更加具体 并提供了我所尝试的完整解释和代码 背景 我需要模仿谷歌日历在顶部有一个视图的方式
  • JavaScript 中的构造函数或对象继承

    我是 JavaScript 新手 本周开始学习 我已经完成了 CodeCademy 课程 实际上只是对象 1 2 部分 其余的很无聊 我以为我学会了构造函数的原型继承 但我已经开始观看了Douglas Crockford 高级 JavaSc
  • 在两个curl请求之间保存cookie

    我知道使用cURL我可以使用以下命令查看收到的 cookie 标头 curl head www google com 我知道我可以使用以下方法将标头添加到我的请求中 curl cookie Key Value www google com
  • Android 以编程方式重置出厂设置

    我尝试使用 RecoverySystem 类在 Android 中执行恢复出厂设置 但出现权限错误 但我无法覆盖这些错误 因为它们是系统权限 我想知道是否还有其他方法可以恢复出厂设置 第三方应用程序绝对可以做到这一点 在 2 2 设备 包括
  • 将 LUIS 对话框连接到表单对话框并映射正确的字段

    我正在开发一个可以预订航班的机器人 我正在使用最新版本的机器人框架 1 1 如建议 https stackoverflow com questions 36712912 mapping luis entities to dialog fie
  • 特征返回特征:在某些情况下有效,在其他情况下无效

    我需要实现一个返回的特征futures StreamExt trait 一般来说 这听起来很简单 并且有几个答案 例如这里 https stackoverflow com questions 60143046 how can a rust
  • 在小提琴图上绘制群图会更改 ylim 并截断小提琴

    import seaborn as sns import numpy as np for sample data import pandas as pd sample data np random seed 365 rows 60 data
  • 如何在Python中将字符串列表转换为字典[重复]

    这个问题在这里已经有答案了 我有一个字符串列表 我想转换成字典 我在抓取数据后得到了输出 Name Dr Mak Location India Delhi Name Dr Hus MD Location US NY 我想要如下输出 Name
  • CQRS-最终一致性

    我有以下场景 需要按照 CQRS 模式来实现 用户登录 用户输入一些保险详细信息 用户请求应用决定 用户查看决策结果 这看起来相当简单 但是我的问题是在步骤 3 和 4 之间 在步骤 3 中我发送了一个ApplyForDecision命令将
  • 来自 Spring Hateoas 的文档 HAL“_links”(带有招摇)? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我想为我的客户开发团队记录一个 REST 服务 所以我添加了一些Links from Spring H
  • 将mat文件转换为pandas dataframe问题

    你好 我一直致力于将 matlab 矩阵良好地转换为 pandas 数据帧 我转换了它 但我有一行 其中有列表列表 这些列表通常是我的行 import pandas as pd import numpy as np from scipy i
  • Qi Symbols 性能慢?

    我想提出一个让我掉进兔子洞的话题 并提出了一个关于 气 符号 这一切都是在我研究新的野兽图书馆并阅读时开始的A 教程示例 http www boost org doc libs 1 66 0 libs beast example http
  • 如何更改标记图标?

    我想知道是否有办法改变那些用作标记的红色别针 如果有办法的话 该怎么做呢 您可以在地图视图中使用以下 3 种颜色图钉 MKPinAnnotationColorGreen MKPinAnnotationColorPurple MKPinAnn
  • 在 Mac OS X Lion 上安装 pymssql 时出错

    我安装了 XCode 和 FreeTDS 我尝试连接到我的 SQL Server 它工作得很好 现在我必须在 python 上开发一个与此 SQL Server 配合使用的应用程序 并且我正在尝试安装 pymysql 但是当我启动 sudo
  • Zoomable JScrollPane - setViewPosition 无法更新

    我正在尝试编写一个可缩放图像在 JScrollPane 中 当图像完全缩小时 它应该水平和垂直居中 当两个滚动条都出现时 缩放应始终相对于鼠标坐标进行 即在缩放事件之前和之后图像的同一点应位于鼠标下方 我已经快要达到我的目标了 不幸的是 s