2
我正在为Java Helper Library写一个方法来显示一个“无窗口”摆动组件(图像),它可以用来显示进度轮或其他东西。前段时间我在asked how to do this,收到了我正在使用的一个很好的答案。它的效果很好,除了the animated gif没有动画。(我没有使用图片本身,因为在阅读此图片的整个过程中看到它可能会使你生病......)它不会动画,因为它不会移动。这似乎已暂停或什么。另一个问题的答案是,动画GIF可以正常工作。答案是-ER错还是我执行这个错误?:为什么这个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。对于图片,尝试热链接http://pscode.org/media/starzoom-thumb.gif或(更小)http://1point1c.org/gif/thum/plnttm.gif –
我会从只使用在事件派发线程中对组件进行Swing,并查看它是否改变了某些内容。 http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html –
@AndrewThompson,我通常对发布真正的SSCCE非常好。我将删除关于SSCCE的那部分内容。我会包括它,但我发现你是对的。该方法是问题所在。从网址获取图片后,效果很好。如果你想发布你的答案,我会接受它。感谢您的关注。 – kentcdodds