0
我很抱歉發佈了與此類似的線程。但我仍然有一些問題。線程可以看到here在drawingPanel中刷新圖片擴展JPanel 2
我正在申請一個jpanel的backfround。我需要有一個加載gifthat稍後改變一個好的或錯誤的圖像。
我在開始加載一個透明圖片。一旦動作監聽器開始加載一個,並且在監聽器中執行的代碼的末尾,我會用ok/error更改圖形。透明,好的和錯誤的一個完美加載,但我沒有設法看到加載之一。
這裏是我的監聽器代碼:
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();
}
我認爲這是asyncronous消息的問題,因爲如果我叫等待剛過
this.iconPanel.repaint();
我可以看到加載GIF。但我的代碼卡在那裏。 所以我想我應該找到一種方法來強制在這一點上執行隊列中的所有命令,但我不知道該怎麼做。
沒有人有類似的問題擺動?
對不起,我不明白。這不是加載圖像的問題,問題是我的應用程序不刷新接口。因爲它工作的3/4倍。但只是當接近「不工作時間」... 你能更好地解釋我是什麼意思? tnx :) – Stefano
*「你能更好地解釋我說的是什麼意思嗎?」*你可以發佈一個[tag:SSCCE]給我使用嗎? –