【发布时间】:2012-05-21 05:55:48
【问题描述】:
我正在为Java Helper Library 编写一个显示“无窗口”摆动组件(图像)的方法,该组件可用作显示进度轮或其他东西的一种方式。不久前我asked how to do this 收到了一个很好的答案,我正在使用它。它很好用,除了 the animated gif 没有动画。 (我没有使用图像本身,因为在你阅读的整个过程中看到它可能会让你生病......)它不是动画的在它不动。它似乎暂停或什么的。另一个问题的答案说动画 gif 可以正常工作。答案是错的还是我执行错了?:
public static void main(String[] args) throws IOException, InterruptedException {
Image image = SwingHelper.resizeImageFromResourceBy(TestClass.class, progressImageLocation, 32, true); //This just gets the image in the right size I want it.
JWindow window = SwingHelper.getProgressWheelWindow(new ImageIcon(image), .9f, 600, 400);
window.setVisible(true);
Thread.sleep(3000); //Just so the image only shows up for a short period of time.
window.setVisible(false);
SwingHelper.centerAndPack(window); //A method to center and pack the window
}
/**
* Returns a window with a partially opaque progress Icon
*
* @param icon the icon to set in the progress window
* @param opacity a float value from 0-1
* @param x the x location of the window
* @param y the y location of the window
* @return a jWindow of the progress wheel
*/
public static JWindow getProgressWheelWindow(final Icon icon, final Float opacity, final int x, final int y) {
JWindow jWindow = new JWindow() {
{
setOpacity(opacity);
setLocation(x, y);
setSize(icon.getIconWidth(), icon.getIconHeight());
add(new JLabel(icon));
pack();
}
};
return jWindow;
}
【问题讨论】:
-
该代码不会复制/粘贴/编译。它不是 SSCCE。对于图像,尝试热链接到pscode.org/media/starzoom-thumb.gif 或(较小的)1point1c.org/gif/thum/plnttm.gif
-
我会首先在事件调度线程中使用 Swing 组件,看看它是否会改变一些东西。 docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html
-
@AndrewThompson,我通常很擅长发布真正的 SSCCE。我将删除有关 SSCCE 的部分。我会包括它,但我发现你是对的。那个方法就是问题所在。从网址获取图像后,效果很好。如果你想发布你的答案,我会接受。感谢您的调查。