简体   繁体   中英

How do I get the image from a imageicon in a jlabel or jbutton?

I am trying to use the draw method and I need to get Image from the jlabel or jbutton but don't know how to exactly do this, anyone know how? Something like this for example

g.drawImage(tiles[(bounds[0]+j)%Map.width][i].getIcon().getImage(), 0, 0, null); 

but this obviously doesn't work with tiles[(bounds[0]+j)%Map.width][i] being a jlabel

I assume you already have a working ImageIcon , and you only need to include it in your JLabel (as stated in the title of the question).

As explained in the JLabel tutorial, you can create labels with an image and text, text only or image only. For the latter, use the new JLabel( icon ) constructor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM