• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java drawimage on jlabel

 
sammy young
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please i have a class that extends jlabel and draw on it using paintComponent as follows this is paintPhotos.java



when i try to draw from a constructor of another class like this (AddScore.java).



the above work fine and draw the image as specified.

but when i try to draw the image from an actionperform event of another class (AddScore.java) like this.



the above statement did not work as the paintcomponent is not working, what am i doing wrong?
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please edit your question and to notify about crossposting on another Java forum
 
sammy young
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my question is, i want to drawimage on jlabel or jpanel when an event occur like actionperformed, so in my actionperformed i did somthing like this

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Image imag = new ImageIcon(this.getClass().getResource("img/top_bg.jpg")).getImage();
showPix1.setLayout(new BorderLayout());
showPix1.add(new paintPhotos(imag,20,20), BorderLayout.CENTER);
}

But is not working, can someone help me out here?
 
Maneesh Godbole
Saloon Keeper
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why reinvent the wheel? Check out the API docs for a method in JLabel which would let you set an icon (hint)
 
Campbell Ritchie
Sheriff
Pie
Posts: 50189
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn,
Your post was moved to a new topic.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50189
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I, earlier wrote:Michael Dunn,
Your post was moved to a new topic.
Any discussion about posting twice should move to that new topic, please.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic