【问题标题】:display gifs in java jars using eclipse使用 eclipse 在 java jar 中显示 gif
【发布时间】:2018-01-22 20:57:06
【问题描述】:

您好,我不确定如何格式化我的动画 gif 图像以让它们显示在 eclipse 上创建的罐子上。

try {
        //ImageIcon titleIcon = new ImageIcon(ImageIO.read(getClass().getResource("title.gif")));
        title = new ImagePicture (new ImageIcon(ImageIO.read(getClass().getResource("title.gif"))), 0, 0);
        //title = new ImagePicture (new ImageIcon("title.gif"), 0, 0);

    }//end try 
    catch (IOException e) {

    }//end catch

    //set title bounds
    title.setBounds(260, 0, 400, 100);

这是我现在的 GIF 动画代码,感谢您的输入。

【问题讨论】:

  • 您要查找的搜索词是“Swing 中的动画 gif”。 Eclipse(您的 IDE)和 jars(您的运行时)与此处无关。
  • ImageIO 不支持动画 Gif,至少不支持任何合理的方式,而直接使用 ImageIcon 是无法实现的。相反,将URLgetResource 直接传递给ImageIcon

标签: java jar animated-gif


【解决方案1】:

如果没有更多上下文,很难给出一个很好的例子,但您可以尝试将 ImageIcon 添加到这样的 JLabel 中。

URL url = this.getClass().getResource("title.gif");
Icon title = new ImageIcon(url);
JLabel titleLbl = new JLabel(title);
//You have to add titleLbl to a container after this, of course

【讨论】:

    猜你喜欢
    • 2012-09-15
    • 2019-05-03
    • 2013-03-22
    • 2018-03-04
    • 1970-01-01
    • 2013-01-07
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多