开发者

Refreshing picture in drawingPanel extends JPanel 2

开发者 https://www.devze.com 2023-03-25 21:28 出处:网络
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 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.repa开发者_StackOverflowint();
    }

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号