【问题标题】:Why is this gif not animated?为什么这个gif没有动画?
【发布时间】: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;
}

【问题讨论】:

标签: java swing animation


【解决方案1】:
SwingHelper.resizeImageFromResourceBy(
    TestClass.class, progressImageLocation, 32, true); 
    //This just gets the image in the right size I want it. 

我对 SSCCE 的最佳猜测是,辅助方法返回原始图像的 静态(调整大小)版本。

请注意,通过在标签中使用 HTML,动画 GIF 可以“即时”调整大小,但效果并不理想。最好把图片设计成合适的尺寸。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-23
    • 1970-01-01
    • 2018-07-09
    • 2015-07-03
    • 2014-03-16
    • 1970-01-01
    相关资源
    最近更新 更多