I have a JPanel which is positioned to fill a JFrame and this panel has
other sub-panels arranged in a GridLayout. Is it possible to do some
rendering of lines, rectangles etc. in the surrounding panel in such a way
that the graphics appear in front of all the sub-panels? I need to do some
rendering that is limited to the surrounding panel but which cuts across
some of the sub-panels and appears in front of them.

Signature
Regards,
Jarrick
------------------------------------
Jarrick.Chagma@your.mind.gmail.com
(Lose your mind before emailing me)
Thomas A. Russ - 29 Jun 2009 21:32 GMT
> I have a JPanel which is positioned to fill a JFrame and this panel has
> other sub-panels arranged in a GridLayout. Is it possible to do some
> rendering of lines, rectangles etc. in the surrounding panel in such a
> way that the graphics appear in front of all the sub-panels? I need to
> do some rendering that is limited to the surrounding panel but which
> cuts across some of the sub-panels and appears in front of them.
I would think that if you created your own subclass of JPanel and
overrode the paintComponent method, you could do this. Just have the
paintComponent method call the super method, and then do your own
rendering. That would cause the panel's items to appear on top.

Signature
Thomas A. Russ, USC/Information Sciences Institute
Knute Johnson - 29 Jun 2009 22:32 GMT
> I have a JPanel which is positioned to fill a JFrame and this panel has
> other sub-panels arranged in a GridLayout. Is it possible to do some
> rendering of lines, rectangles etc. in the surrounding panel in such a
> way that the graphics appear in front of all the sub-panels? I need to
> do some rendering that is limited to the surrounding panel but which
> cuts across some of the sub-panels and appears in front of them.
How about the GlassPane of the JFrame?
http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html

Signature
Knute Johnson
email s/nospam/knute2009/
Christian Kaufhold - 03 Jul 2009 15:43 GMT
> I have a JPanel which is positioned to fill a JFrame and this panel has
> other sub-panels arranged in a GridLayout. Is it possible to do some
> rendering of lines, rectangles etc. in the surrounding panel in such a way
> that the graphics appear in front of all the sub-panels? I need to do some
> rendering that is limited to the surrounding panel but which cuts across
> some of the sub-panels and appears in front of them.
A component cannot easily paint something on top of its children because
the children may be repainted directly without the parent knwoing.
There are basically two ways to do it:
a) add a bogus transparent child at the beginning which covers the whole component
(You need to override isOptimizedDrawingEnabled()!)
or
b) add a bogus transparent sibling after the component (then the parent
needs to override isOptimizedDrawingEnabled()).
The you can override paintChildren(Graphics) and paint after super.paint-
Children().
Also see: http://groups.google.com/group/comp.lang.java.gui/browse_thread/thread/579a14b53
0ef30f2/57d8c6d454e5f862