• Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying image on JWindow

 
Shyam Purkayastha
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I was just trying to add and display an image on a Jwindow using the following code.
import javax.swing.*;
import java.awt.*;

public class splash
{
static Image i = Toolkit.getDefaultToolkit().getImage("image/splash.jpg");

public static void main(String args[]){

JWindow jw = new JWindow(){

public void paint(Graphics g){

g.drawImage(i,0,0,i.getWidth(this),i.getHeight(this),this);

}
};


jw.setSize(500,300);
jw.setVisible(true);



}
}
The Jwindiw is display but it is blank hence no image gets displayed in it.
Is there anything wrong with the code or it has some other technique of doing it?
please help
shyam
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using a media tracker to track progress of your image loading. Once it is completed do a repaint. Larger images may not be loaded imediately and thus can not be displayed right away, and no repaint will be called until some event forces it (like moving the window or something). So you will have to add your own repaint when the media tracker detect the image is done loading...
Steve
 
Shyam Purkayastha
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem was with the file extension
I had given .jpg but it should be .jpeg
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!