I have class MyPanel that extends from JPanel. MyPanel class has JLabel component which holds an icon.
My question is how can i paint/render this JLabel component to get translucent effect (see through icon) inside MyPanel class (not create xxxJLabel extends JLabel class and override paintComponents method).
Thank you
One way is to provide a translucent image to the
JLabel. That might be done with a standard label, beforesetIcon()or similar is called, or alternately by extendingJLabeland overriding thesetIcon()method to do the same.E.G. of 2nd technique
Code
Update
LabelRenderTest.java renders a
JLabelto aBufferedImageso that it can be used for custom rendering inside thepaintComponent(Graphics)method.Note though: I don’t quite understand what the advantage of the
JLabelis in your use-case. I was using it in that example in order to render HTML. If I only had an image, I’d use the image directly (e.g.Graphics.drawImage(Image,int,int,ImageObserver)) and never create the label.