• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Background Image not showing

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



 
Sheriff
Posts: 22816
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 3324
32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did provide some code. Its called reading the tutorial and downloading the example code!
 
Rob Spoor
Sheriff
Posts: 22816
132
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The frame your showing and the frame with the image are not the same.
 
Rimp chalotra
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic