Help with layering graphics and components on JLayeredPane

I have a JLayeredPane in which in need to add different components to it and have them be layered one on top of the other, therefore I am adding a components to the JLayeredPane using the method add(Component comp, int index) and choose an appropriate index to specify the layer.

My challenge begins in that I am also overriding the paint(Graphics g) method and using the graphics object to draw a filled rectangle on the JLayeredPane which is updated/repainted once a second. The other components (JPanels) are only updated upon resize of the JLayeredPane and are specified on layers 1-3.

The problem that i am facing is that the filled rectangle is painted on top of the other components that i have added to the JLayeredPane where i would like it added behind.

Is there a way that i can specify an index for a layer to use for the graphics object so that it stays behind the other components that are added? Or do i need to re-design and try to use a JPanel instead of the Graphics object? Thanks in advance for any help. -

Message was edited by:

b12s

[1095 byte] By [b12sa] at [2007-11-27 3:35:38]
# 1

I have resolved my issues by using the JLayerdPanes add() method to specification and re-implementing my structure. (Amazing what can happen when you follow the directions! :)). Thanks anyway for taking a look. If anyone has any comments about how to layer the graphics component of a JLayeredPane I would still be interested to hear that. thanks

b12sa at 2007-7-12 8:38:49 > top of Java-index,Desktop,Core GUI APIs...
# 2
Hello. I think I have the same problem. I have a JlayeredPane with Button, Images , etc...and now I want to draw rectangles behind the buttons. How can I do that? the add() method is just for Components, not for Rectangles...Can you help me? Thanks!
fluis84a at 2007-7-12 8:38:49 > top of Java-index,Desktop,Core GUI APIs...