This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Background Image not showing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Background Image not showing" Watch "Background Image not showing" New topic
Author

Background Image not showing

Rimp chalotra
Greenhorn

Joined: Sep 26, 2011
Posts: 4

hi all, greetings !
I am trying to write a simple swing program which displays an image in it. But i am getting a blank frame, the image is not showing. Please help !


Here is the code and "D:/boy.png" is address of the picture on my hard drive......Thanks


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

Rimpika chalotra wrote:"D:/boy.png" is address of the picture on my hard drive......


Those don't match, do they?

And please uncomment that line, you need that call.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2180
    
    7
1. Don't know what the Timer is used for, so get rid of it.
2. Don't know why you have a paint() method. An ActionListener doesn't use this method.

Start with the basics and use a JLabel to display an Image. See the section from the Swing tutorial on How to Use Icons for an example.
Rimp chalotra
Greenhorn

Joined: Sep 26, 2011
Posts: 4
Rob Spoor wrote:
Rimpika chalotra wrote:"D:/boy.png" is address of the picture on my hard drive......


Those don't match, do they?

And please uncomment that line, you need that call.



The adress of the image in the hard drive is actually the one in code that is: "D:/images.jpg", I pasted the wrong address("D:/boy.png") by mistake.
and i have Uncommented the call to super.paint(g) method. But its still not showing the image.



The modified code is as following:


Rimp chalotra
Greenhorn

Joined: Sep 26, 2011
Posts: 4
Rob Camick wrote:1. Don't know what the Timer is used for, so get rid of it.
2. Don't know why you have a paint() method. An ActionListener doesn't use this method.

Start with the basics and use a JLabel to display an Image. See the section from the Swing tutorial on How to Use Icons for an example.


I had that timer and ActionListener interface for something else, anyhow i have updated the code, so please see it and if possible provide some code...Thanks
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2180
    
    7
I did provide some code. Its called reading the tutorial and downloading the example code!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

The frame your showing and the frame with the image are not the same.
Rimp chalotra
Greenhorn

Joined: Sep 26, 2011
Posts: 4
Rob Spoor wrote:The frame your showing and the frame with the image are not the same.


Yes, its showing it now, thanks for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Background Image not showing