Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
免费Java Swing组件,使用zoom+;滚动->;受通缉的_Java_Swing - Fatal编程技术网

免费Java Swing组件,使用zoom+;滚动->;受通缉的

免费Java Swing组件,使用zoom+;滚动->;受通缉的,java,swing,Java,Swing,我似乎找不到一个Java Swing库,可以用来在JPanel中轻松显示图像,并允许用户滚动、平移和缩放。有什么想法吗?谢谢 我目前正在使用以下代码在JPanel中显示图像,但这是非常基本的 我真的很想快速介绍缩放、滚动和平移功能 final BufferedImage img; try { img = ImageIO.read(image_file); } catch (IOException e) { thr

我似乎找不到一个Java Swing库,可以用来在JPanel中轻松显示图像,并允许用户滚动、平移和缩放。有什么想法吗?谢谢

我目前正在使用以下代码在JPanel中显示图像,但这是非常基本的

我真的很想快速介绍缩放、滚动和平移功能

    final BufferedImage img;

    try
    {
        img = ImageIO.read(image_file);

    }
    catch (IOException e)
    {
        throw new XCustomErrorClass("Could not open image file", e);
    }

    JPanel image_panel = new JPanel(new BorderLayout(0, 0)) 
    {
        protected void paintComponent(java.awt.Graphics g) 
        {
             super.paintComponent(g);
             g.drawImage(img.getScaledInstance(getWidth()-20,-1, Image.SCALE_FAST), 10, 10, this);

        };
    };

要滚动,请将面板放入JScrollPane中

对于缩放和平移,可以根据鼠标侦听器中维护的一些变量在paintComponent中变换Graphics2D对象。大概是这样的:

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;

    // Backup original transform
    AffineTransform originalTransform = g2d.getTransform();

    g2d.translate(panX, panY);
    g2d.scale(zoom, zoom);

    // paint the image here with no scaling
    g2d.drawImage(img, 0, 0, null);

    // Restore original transform
    g2d.setTransform(originalTransform);
}

要求我们推荐或查找书籍、工具、软件库、教程或其他非现场资源的问题对于堆栈溢出来说是离题的,因为它们往往会吸引自以为是的答案和垃圾邮件。相反,请描述问题以及迄今为止为解决问题所做的工作。哦,对不起,添加了我当前的代码谢谢!我想实现这一点不会太困难。但是如果有人知道Swing组件,请建议-重用现有代码是开发IMHO的一个非常现实的方面