Java swing won't display g.drawImage() until repaint() is called -


@override public void paintcomponent(graphics g) {     graphics2d g2 = (graphics2d) g;     super.paintcomponent(g2);      g2.fillrect(20, 20, 200, 200);     g2.drawimage(map, 0, 0, 1004, 687, null); } 

this code paintcomponent in jpanel.

when application launched, can see rectangle (which there because wanted check if paintcomponent being called). the map doesn't draw until force repaint resizing window or pressing button forces repaint().

i tried calling validate() in several places because answers suggested that, didn't work.

g2.drawimage(map, 0, 0, 1004, 687, null); 

try using:

g2.drawimage(map, 0, 0, 1004, 687, this); 

maybe image isn't read @ time paintcomponent() method invoked. "this" cause image painted when i/o finished. panel notified i/o done , panel repaint itself.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -