DrawingPanel中的刷新图片扩展了JPanel 2
我很抱歉发布了与此非常相似的帖子。但我仍然遇到一些问题。可以看到线程这里
我正在将后台应用到j 面板。我需要一个加载 gif,稍后会更改为正常或错误图像。
我在开始时加载一张透明图片。一旦动作侦听器通过加载侦听器启动,它就会被替换,并且在侦听器中执行的代码结束时,我用 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();
}
我认为这是异步消息的问题,因为如果我在
this.iconPanel.repaint();
看到加载 gif 后立即调用 wait 。但我的代码卡在那里。 所以我认为我应该找到一种方法来强制执行队列中的所有命令,但我不知道该怎么做。
有人在使用 swing 时遇到过类似的问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用诸如
ImageIO.read(File/URL/InputStream)
之类的阻塞方法来获取Image
。ImageIO
最近被引入到 J2SE 中。Use a blocking method such as
ImageIO.read(File/URL/InputStream)
to get theImage
.ImageIO
has been introduced into the J2SE 'recently'.