相关疑难解决方法(0)

在JLabel怪异中加载动画GIF

我正在尝试在JLabel中加载动画GIF.

虽然这有效:

URL urlsd;
try {
    urlsd = new URL("http://pscode.org/media/starzoom-thumb.gif");
    ImageIcon imageIcon = new ImageIcon(urlsd); 
    JLabel progress = new JLabel(imageIcon);    
    progress.setBounds(5, 20, 66, 66);
    contentPane.add(progress);
} catch (MalformedURLException e) {
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

另一方面,这不,并且我不想从URL获取GIF,因为我已经拥有GIF.加载结果只显示GIF的第一帧:

try {   
    ImageIcon imageIcon = new ImageIcon(ImageIO.read(ClassLoader.getSystemResourceAsStream("res/images/progress_indicator.gif")));

    JLabel progress = new JLabel(imageIcon);
    imageIcon.setImageObserver(progress);
    progress.setBounds(5, 20, 66, 66);
    contentPane.add(progress);
} catch (MalformedURLException e) {

    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

我想这肯定是有原因的,但我找不到它.

谢谢!亚历克斯

java swing jlabel animated-gif

6
推荐指数
1
解决办法
1万
查看次数

从ArrayList <List> - Java每X秒更新一次JLabel

我有一个简单的Java程序,它读入一个文本文件,用""(空格)分割,显示第一个单词,等待2秒,显示下一个...等...我想在Spring中执行此操作或一些其他的GUI.

关于如何用spring轻松更新单词的任何建议?迭代我的列表并以某种方式使用setText();

我没有运气.我正在使用这种方法在consol中打印我的单词并将JFrame添加到它...在consol中工作得很好,但是输出了无穷无尽的jframe.我在网上找到了大部分内容.

    private void printWords() {
        for (int i = 0; i < words.size(); i++) {
            //How many words?
            //System.out.print(words.size());
            //print each word on a new line...
            Word w = words.get(i);
            System.out.println(w.name);

            //pause between each word.
            try{
                Thread.sleep(500);
            } 
            catch(InterruptedException e){
                e.printStackTrace();
            }
         JFrame frame = new JFrame("Run Text File"); 
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
         JLabel textLabel = new JLabel(w.name,SwingConstants.CENTER);
         textLabel.setPreferredSize(new Dimension(300, 100)); 
         frame.getContentPane().add(textLabel, BorderLayout.CENTER);
        //Display the window. frame.setLocationRelativeTo(null); 
         frame.pack(); 
         frame.setVisible(true);
        }
    }
Run Code Online (Sandbox Code Playgroud)

我有一个用JFrame和JLable创建的窗口,但是,我希望静态文本是动态的,而不是加载一个新的弹簧窗口.我想它闪现一个字,消失,闪现一个字消失.

有关如何更新JLabel的任何建议?什么与重绘()?我画了一个空白.

谢谢!

更新: 在下面的亲切的帮助下,我已经让它正确打印到控制台.这是我的打印方法:

private void printWords() {
            final …
Run Code Online (Sandbox Code Playgroud)

java concurrency swing timer freeze

3
推荐指数
2
解决办法
9518
查看次数

更新JLabel中包含的图像 - 问题

我目前无法开始工作的应用程序的一部分是能够滚动并一次显示一个图像列表.我从用户那里得到一个目录,绕过该目录中的所有文件,然后加载一个只有jpegs和png的数组.接下来,我想用第一个图像更新JLabel,并提供上一个和下一个按钮来滚动并依次显示每个图像.当我尝试显示第二个图像时,它没有得到更新...这是我到目前为止所得到的:

public class CreateGallery
{
    private JLabel swingImage;
Run Code Online (Sandbox Code Playgroud)

我用来更新图像的方法:

protected void updateImage(String name) 
{
    BufferedImage image = null;
    Image scaledImage = null;
    JLabel tempImage;

    try
    {
        image = ImageIO.read(new File(name));
    } catch (IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // getScaledImage returns an Image that's been resized proportionally to my thumbnail constraints
    scaledImage = getScaledImage(image, THUMB_SIZE_X, THUMB_SIZE_Y);
    tempImage = new JLabel(new ImageIcon(scaledImage));
    swingImage = tempImage;
}
Run Code Online (Sandbox Code Playgroud)

然后在我的createAndShowGUI方法中放置swingImage ...

private void createAndShowGUI() 
{
    //Create and set up the …
Run Code Online (Sandbox Code Playgroud)

java swing image jlabel

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×3

swing ×3

jlabel ×2

animated-gif ×1

concurrency ×1

freeze ×1

image ×1

timer ×1