• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying image on JWindow

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem was with the file extension
I had given .jpg but it should be .jpeg
 
Slime does not pay. Always keep your tiny ad dry.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic