Forums Register Login

custom JTree icons

+Pie Number of slices to send: Send
Hi there,
I'm trying to do a small project where I can display my own icons in a JTree. However, when I attempt to run the code below the icons don't get displayed. I've tried various combinations of code all resulting the same, no icons.
Please look over my code and tell me where I went wrong.
Thanks,
Alan

[ October 14, 2003: Message edited by: Michael Ernest ]
+Pie Number of slices to send: Send
I'll move this to the Swing forum where you're bound to get a quick response.
+Pie Number of slices to send: Send
if you get a NullPointerException?
i think:
if you can insure images/xxx.gif in you classpath
the code is right.
+Pie Number of slices to send: Send
hi first check whether the image is loading properly. because if the image is not loaded or if it is not the location no error is thrown. if all r ok then try the below method.
getTreeCellRendererComponent(JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus)
override this method and check whether the node is leaf or closed or opened and then set the icon.
hope this helps u
Marcus
Everybody's invited. Even this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1059 times.
Similar Threads
setting JTree icons
custom icons in JTree
JTree double click
plus/minus sign in a jtree
jTree with the TreeModel
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:29:02.