我正在为Java Helper Library编写一个方法来显示一个“无窗口”摆动组件(图像),它可以用作显示进度轮或其他东西的一种方式。不久前我问过如何做到这一点,并收到了我正在使用的一个很好的答案。它工作得很好,除了动画 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;
}