Swing 无窗组件? [英] Swing Windowless Component?

查看:68
本文介绍了Swing 无窗组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在处理某些事情时显示一个旋转的进度轮(例如 this)向用户展示正在发生的事情.有什么办法可以在不为它弹出整个窗口的情况下做到这一点吗?我正在使用摇摆.谢谢.

I want to show a spinning progress wheel thing (like this) when something's processing to show the user something's happening. Is there any way I can do this without popping up a whole window for it? I'm using swing. Thanks.

推荐答案

这里有两个精简的说明示例,说明如何在屏幕上弹出显示图像.根据需要调整图片来源、位置、大小、异常处理等.

Here are two stripped-down instructional examples of how to pop-display an image on the screen. Adjust image source, position, size, exception handling etc. as necessary.

示例 1,共 2 个,使用 JLabel 的半透明:

Example 1 of 2, Semi-transparent using JLabel:

public static void main(String args[]) throws Exception {
JWindow jWindow = new JWindow() {
final Icon icon = new ImageIcon(<yourImage>);  // Okay to be animated
{
    setOpacity(.642f);
    setLocation(0,0);
    setSize(icon.getIconWidth(), icon.getIconHeight());
    add(new JLabel(icon));
    pack();
}
};
jWindow.setVisible(true);
Thread.sleep(3000);
jWindow.setVisible(false);
}

示例 2(共 2 个),使用油漆透明:

Example 2 of 2, Transparent using paint:

public static void main(String args[]) throws Exception {
JWindow jWindow = new JWindow() {
final Image image = ImageIO.read(<yourImage>);  // Static image only
{
    setLocation(0,0);
    setSize(image.getWidth(), image.getHeight());
}
public void paint(Graphics g) {
    g.drawImage(image, 0, 0, null);
}
};
jWindow.setVisible(true);
Thread.sleep(3000);
jWindow.setVisible(false);
}

这篇关于Swing 无窗组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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