• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Displaying image on JWindow

 
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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!