taborrg
asked on
Is there a way to make a jlist transparent?
Hi,
Is there a way to make a jlist transparent?
Thanks
Is there a way to make a jlist transparent?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I saw the first link earlier, but couldn't make sense of it.
The second link lots like I might be able to follow it. Will probably take a day.
Thanks
The second link lots like I might be able to follow it. Will probably take a day.
Thanks
about the first link.
This link
http://docs.oracle.com/javase/6/docs/api/javax/swing/JList.html
goves an example of using ListCellRenderer with the list.
The main method of ListCelllRenderer
public Component getListCellRendererCompone nt(..)
needs to return a subclass of JComponent - they show how to use
subclass of JLabel to return from this method by creating MyListCellRenderer extending JLabel. Then making JList transparent will be the same as making JLabel's, returned for each cell, transparent, which you should be able to achieve by using setOpaque(false)
in the end where this method returns JLabel, like in this place
setOpaque(true); // change this to false
return this;
It looks like the asker in that case tried and was happy with that.
It seems to me it should work either.
Anyway try the second one if that one is closer to what you like to achieve
This link
http://docs.oracle.com/javase/6/docs/api/javax/swing/JList.html
goves an example of using ListCellRenderer with the list.
The main method of ListCelllRenderer
public Component getListCellRendererCompone
needs to return a subclass of JComponent - they show how to use
subclass of JLabel to return from this method by creating MyListCellRenderer extending JLabel. Then making JList transparent will be the same as making JLabel's, returned for each cell, transparent, which you should be able to achieve by using setOpaque(false)
in the end where this method returns JLabel, like in this place
setOpaque(true); // change this to false
return this;
It looks like the asker in that case tried and was happy with that.
It seems to me it should work either.
Anyway try the second one if that one is closer to what you like to achieve
ASKER
I appreciate the explanation - I'll take another look at it.
ASKER
Thanks for the help.
http://www.dreamincode.net/forums/topic/183398-how-to-make-jlist-transparent/
Re: How to make JList transparent?
Posted 27 July 2010 - 10:09 AM
I *THINK* you need to the cell renderer to be transparent too. This may involve making your own custom cell renderer. The API has an example of how to do that. You can probably copy their example and modify it to suit your needs (setting it to non-opaque, of course).
API link:
http://docs.oracle.com/javase/6/docs/api/javax/swing/JList.html