I am trying to use a JLayeredPane containing a root JPanel with an image as a background and several toggleable layers with JPanels as the same size as the icon in the root JPanel. When I make any of the higher levels visible, the JPanel covers the entire image in the layer below. Is their a way to make this transparent--i.e., not draw the grey background? Maybe there is a better way to do layered image manipulation? Jason Robey
Turns out that with a layout manager (as is documented in the API) layering information is ignored. So even if my JPanel is set to transparent, the layout managers I tried only look at the top (this is because all my frames are of the same size in different layers). So, I got it to work making each layer a JLabel and using setBounds to give them all the same size. I used setIcon on each JLabel to an implementation of icon specific to the function of each layer. My only issue now is efficiency. For the small set of things I am dealing with, what I have works. The painting of the specialty icons seems to slow my application down more than necessary, but only when I have an area with several objects in the view space of my scroll pane. If anyone has any ideas on how to make this more efficient, I'm all ears. Thanks.
Why not make a custom Icon subclass that can turn on and off "overlay" icons on top of a default background icon... I don't think that multiple overlapping components are a good idea, as you get overhead from the extra components, but all you really want is part of your icon altered. (At least, that's what it sounds like from your post...)
Something kind of like this:
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Thanks, I'll try that. Shaded polygons is definitely an efficiency issue right now that caching in an image/imageIcon might fix. I was able to make some improvement via VolitileImage double-buffering, but it remains a bit choppy on scrolling. I'll try the single icon approach and see if I can't cache some of the filled polygon drawing for components that don't move. Jason
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
SKIP - a book about connecting industrious people with elderly land owners