将鼠标悬停在缩略图上时显示完整图像为弹出/覆盖 [英] Show full Image when hover over thumbnail as Popup/Overlay

查看:85
本文介绍了将鼠标悬停在缩略图上时显示完整图像为弹出/覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JPanel中显示缩略图。当鼠标悬停在这样的缩略图上时,我希望在缩略图上显示其完整版本。

I display thumbnails in a JPanel. When hovering over such a thumbnail, I want to display its full version in an overlay over the thumbnail.

使用HTML我只会创建一个具有正确位置的div高z-index,以便覆盖其他所有内容。
使用Swing可以实现类似和轻量级吗?

Using HTML I would just create a div with the proper positions and a high z-index, so that it overlays everything else. Is something similiar and lightweight possible with Swing?

推荐答案

一种方法是使用工具提示。

One way is to use a tool-tip.

import javax.swing.*;
import java.awt.GridLayout;

class ThumbTip {

    private static final String HTML = "<html><body>";

    ThumbTip(String[] album) {
        JPanel p = new JPanel(new GridLayout(1,0,2,2));
        for (String url : album) {
            String s = HTML + "<img src='" + url.toString() + "'";
            String size = " width=200 height=150";
            JLabel l = new JLabel(s + size + ">");
            l.setToolTipText(s + ">");
            p.add(l);
        }
        JOptionPane.showMessageDialog(null, p);
    }

    public static void main(String[] args) {
        final String[] urls = {
            "http://pscode.org/media/stromlo1.jpg",
            "http://pscode.org/media/stromlo2.jpg"
        };
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new ThumbTip(urls);
            }
        });
    }
}



注:



Note:


  1. 在此演示中。每次使用时都会从网上下载工具提示图像。耐心点。

  2. 我没有打扰'缩略图'原始图像​​。 '不包括电池'。源的最新编辑使用HTML(宽度 / 高度指定对于图像)缩小'缩略图'。我不会更新截图。

  3. 最终建议使用 JWindow 更好,因为它可以让你更好地控制以及弹出窗口显示的时间长短以及它的确切外观。但这种黑客攻击明显缩短了。 ;)

  1. In this demo. the tool-tip image is downloaded from the net each time it is used. Be patient.
  2. I did not bother to 'thumbnail' the original images. 'Batteries not included'. The latest edit of the source use HTML (the width/height specified for the image) to shrink the 'thumbnails'. I won't update the screenshot.
  3. Ultimately the suggestion of using a JWindow is better, since it gives you more control of where and for how long the pop-up appears, as well as its exact look. But this hack is significantly shorter. ;)

这篇关于将鼠标悬停在缩略图上时显示完整图像为弹出/覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆