aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Java drawimage on jlabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Java drawimage on jlabel" Watch "Java drawimage on jlabel" New topic
Author

Java drawimage on jlabel

sammy young
Greenhorn

Joined: Oct 29, 2012
Posts: 3
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

Joined: Jun 19, 2012
Posts: 155
please edit your question and to notify about crossposting on another Java forum
sammy young
Greenhorn

Joined: Oct 29, 2012
Posts: 3
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

Joined: Jul 26, 2007
Posts: 10451
    
    8

Why reinvent the wheel? Check out the API docs for a method in JLabel which would let you set an icon (hint)


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Michael Dunn,
Your post was moved to a new topic.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java drawimage on jlabel