简体   繁体   English

如何在恢复代码之前等待setIcon()方法执行?

[英]How to wait for setIcon() method to execute before resuming the code?

I have a code that goes like this: 我有这样的代码:

jLabel.setIcon(map);
Graphics2D g = (Graphics2D) jLabel.getGraphics();
g.drawPolygon(xpoints,ypoints,vpolygonpointsarray.length);

But what happens is that the polygon is drawn first before the labels icon is updated. 但是发生的是,在更新标签图标之前先绘制了多边形。 I suspect setting an icon creates a new thread. 我怀疑设置图标会创建新线程。 I would like to wait until the icon is set before the rest of the code is executed. 我想等到图标设置好后再执行其余代码。 How would I do that? 我该怎么做?

You should do your custom painting code in an overridden paint method ( paint() , paintComponents() etc.). 您应该使用覆盖的绘制方法( paint()paintComponents()等)进行自定义绘制代码。 Check here: http://docs.oracle.com/javase/tutorial/uiswing/painting/step2.html 在这里检查: http : //docs.oracle.com/javase/tutorial/uiswing/painting/step2.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM