How do I make an icon's background transparent?

T

Todd

Hello all,

I have created two icons, one with a triangle pointing to the right
and one with a triangle pointing down. Both of the triangles sit upon
a white background in the .jpg files. I am using these icons on
togglebuttons to indicate closed and opened states, respectively.

However, the white background is annoying on a colored panel. I tried
setting the opacity to false, no luck. Does anyone know how I can
make the white background translucent so that the panel color comes
through?

Thanks,
Todd

p.s. The only thing that I have come up with so far is changing the
UI, however, I don't want to write one, if there is one that can do
this for me.
 
M

Manish Pandit

Hello all,

I have created two icons, one with a triangle pointing to the right
and one with a triangle pointing down. Both of the triangles sit upon
a white background in the .jpg files. I am using these icons on
togglebuttons to indicate closed and opened states, respectively.

However, the white background is annoying on a colored panel. I tried
setting the opacity to false, no luck. Does anyone know how I can
make the white background translucent so that the panel color comes
through?

Thanks,
Todd

p.s. The only thing that I have come up with so far is changing the
UI, however, I don't want to write one, if there is one that can do
this for me.

If you are on Windows, use irfanview (http://www.irfanview.com) to
open the jpg images. Then click 'save as', select 'gif' and check the
box that says 'transparent background' or something along those
lines.

For Linux I believe Gimp has something similar.

-cheers,
Manish
 
R

Roedy Green

I have created two icons, one with a triangle pointing to the right
and one with a triangle pointing down. Both of the triangles sit upon
a white background in the .jpg files.

Ordinary JPGs do not support transparency. You need a png or gif.

You normally insert the transparency with your paint program. You can
also create images programatically with transparency using the alpha
channel.

See http://mindprod.com/applet/masker.html
for an example.

You could also create such an image by painting on a custom JPanel.
Don't clear the background. Just paint the arrow. You don't need to
fool about with the alpha channel.

One other way to do it is to find suitable Unicode glyph and use it in
a JLabel with a font that supports it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top