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 496723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:42:47+00:00 2026-05-13T05:42:47+00:00

I’ve got an editor with lots of image thumbnails. I’d like a double-click on

  • 0

I’ve got an editor with lots of image thumbnails. I’d like a double-click on an image to display the full resolution image using a modal undecorated dialog. Ideally, this would be animated, to show the image zooming up to full resolution on the center of the screen, then any click would make the image go away, either zooming back out or fading away.

I’m not concerned with establishing an exact behavior, I just want something slick. I’ve found plenty of JavaScript examples for this, but is there anything built for Swing?

  • 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-05-13T05:42:47+00:00Added an answer on May 13, 2026 at 5:42 am

    This piece of code does more or less the trick…
    There is still a problem in the way I’m setting the dialog’s location…

    Hope it helps.

    import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.geom.AffineTransform;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.lang.reflect.InvocationTargetException;
    
    import javax.imageio.ImageIO;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    
    public class OpenImageZooming {
    
     private static final int NB_STEPS = 30;
    
     private static final long OPENING_TOTAL_DURATION = 3000;
    
     public static void main(String[] args) {
      OpenImageZooming me = new OpenImageZooming();
      me.openImage(args[0]);
     }
    
     private JFrame frame;
     private JDialog dialog;
     private JPanelZooming panelZooming;
    
     private void openImage(final String imagePath) {
      SwingUtilities.invokeLater(new Runnable() {
       public void run() {
        frame = new JFrame();
        frame.setTitle("Open image with zoom");
        JPanel p = new JPanel(new BorderLayout());
        p.add(new JLabel("click on button to display image"), BorderLayout.CENTER);
        JButton button = new JButton("Display!");
        frame.setContentPane(p);
        button.addActionListener(new ActionListener() {
    
         public void actionPerformed(ActionEvent e) {
          Thread t = new Thread() {
    
           @Override
           public void run() {
            displayImaggeWithProgressiveZoom(imagePath);
           }
    
          };
          t.start();
    
         }
    
        });
        p.add(button, BorderLayout.SOUTH);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 100);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
       }
      });
     }
    
     protected void displayImaggeWithProgressiveZoom(String imagePath) {
      try {
       final BufferedImage image = ImageIO.read(new File(imagePath));
    
       for (int i = 0; i < NB_STEPS; i++) {
        displayDialog(i, NB_STEPS, image);
    
        Thread.sleep(OPENING_TOTAL_DURATION / NB_STEPS);
       }
    
      } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
    
     }
    
     private void displayDialog(final int i, final int nbSteps, final BufferedImage image) {
    
      try {
       SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
         if (dialog == null) {
          dialog = new JDialog(frame);
          dialog.setUndecorated(true);
          dialog.setModal(false);
          panelZooming = new JPanelZooming(image);
          dialog.setContentPane(panelZooming);
          dialog.setSize(0, 0);
          dialog.setLocationRelativeTo(frame);
          dialog.setVisible(true);
    
         }
         int w = (i + 1) * image.getWidth() / nbSteps;
         int h = (i + 1) * image.getHeight() / nbSteps;
    
         panelZooming.setScale((double) (i + 1) / nbSteps);
         dialog.setSize(w, h);
         dialog.setLocationRelativeTo(null);
        }
       });
      } catch (InterruptedException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      } catch (InvocationTargetException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
    
     }
    
     @SuppressWarnings("serial")
     public static class JPanelZooming extends JPanel {
    
      private BufferedImage image;
    
      private double scale = 1.0d;
    
      public JPanelZooming(BufferedImage image) {
       this.image = image;
      }
    
      @Override
      protected void paintComponent(Graphics g) {
       super.paintComponent(g);
       Graphics2D g2 = (Graphics2D) g;
       AffineTransform at = g2.getTransform();
       AffineTransform oldTransform = (AffineTransform) at.clone();
       at.scale(scale, scale);
       g2.setTransform(at);
       g2.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null);
       g2.setTransform(oldTransform);
    
      }
    
      public void setScale(double scale) {
       this.scale = scale;
      }
    
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.