0

i apologise for having posted a thread quite similar to this one. but still i am having some problems. thread can be seen here

i am applying a backfround to a jpanel. i need to have a loading gifthat changes later on for a ok or error image.

i load at the beginning a trasparent picture. it get replaced as soon as an action listener starts by the loading one and in the end of the code executed in the listener i change the figure with ok/error. the transparent, the ok and the error one get loaded perfectly but i did not manage to see the loading one.

here is my listener code:

void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {
        
        // load loading icon
        Image img = new ImageIcon(iconPath+"loading.gif").getImage();
        this.iconPanel.replaceImage(img);

        this.iconPanel.updateUI();
        this.iconPanel.revalidate();
        this.iconPanel.repaint();
        
        // clear table contents
        designValue.clear();
        deployValue.clear();

        // Fill class
        diagnosticGenerator diagnostic = new diagnosticGenerator();
        Vector<Integer> indexes;
        
        // if modeCombo.getSelectedIndex() == 0 i show only data regarding the current user
        if (modeCombo.getSelectedIndex() == 0) {
            // receive Design Table
            designValue.addAll(diagnostic.getDesignContents());
    
            // receive Deploy Table
            deployValue.addAll(diagnostic.getDeployContents());
            
            // receive indexes of out-dated deploy
            indexes = new Vector<Integer>(diagnostic.getOutdatedDeployIndexes());
        }
        // otherwise i show data of all the users
        else {
            // receive Design Table
            designValue.addAll(diagnostic.getDesignContents_allUsers());
    
            // receive Deploy Table
            deployValue.addAll(diagnostic.getDeployContents_allUsers());
            
            // receive indexes of out-dated deploy
            indexes = new Vector<Integer>(diagnostic.getOutdatedDeployIndexes_allUsers());

        }

        // set default color to green
        deployTable.resetColor(Color.white);
        // set red background to the
        for (Integer x : indexes) 
            deployTable.setRowColor(x, Color.red);

        deployTable.repaint();
        designTable.revalidate();
        deployTable.revalidate();
        
        //update refreshLabel with the new date
        Date date = new Date();
        refreshLabel.setText(date.toString());
        
        //replace icon with different mark depending on the fact if we found an error or not
        if(indexes.isEmpty())
            img = new ImageIcon(iconPath+"ok.png").getImage();
        else
            img = new ImageIcon(iconPath+"error.png").getImage();
        this.iconPanel.replaceImage(img);
        this.iconPanel.repaint();
    }

i think it's a matter of asyncronous messages because if i call a wait just after

this.iconPanel.repaint();

i can see the loading gif. but my code gets stuck there. So i think i shoud find a way to force at that point to execute all the command in queue but i have no idea how to do it.

does anyone had a similar problem with swing?

1 Answer 1

1

Use a blocking method such as ImageIO.read(File/URL/InputStream) to get the Image. ImageIO has been introduced into the J2SE 'recently'.

2
  • sorry i do not get it. It's not a problem of loading the image, the problem is that my application does not refresh the interface. becase 3/4 times it works. but just when is close to a "not working time"... can you explain me better what do you mean? tnx :)
    – Stefano
    Aug 5, 2011 at 10:13
  • "can you explain me better what do you mean?" Can you post an sscce for me to work with? Aug 5, 2011 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.