How to draw properly in overlapping JInternalFrames?

G

Guest

I'm (still...) working on some inherited code and am trying
to fix a bug where two JInternalFrames that contain JComponents
used as "canvases" draw on each others border's when they
overlap. Each JComponent implements it's own paintComponent()
method, which calls super.paintComponent() and then draws
itself. The two components won't draw on each other, but
if the frames overlap the lower one freely messes up any
part of the overlying frame *except* it's drawing canvas.
(Hope that all made sense, a picture would help I guess but
I've no place to put one right now)

I've found plenty of discussion on the issue various places
on the net, including SUN, but no definitive piece of example
code or clear explanation of how to fix it.

The only way I can see now if to get from the containing
JDesktopPane the locations of all objects above either
JInternalFrame and build a clipping list. This seems like
an awful lot of work, is there something simpler I'm
missing?

Thanks,

--arne

DISCLAIMER: These opinions and statements are those of the author and
do not represent any views or positions of the Hewlett-Packard Co.
 
P

Paul Lutus

I'm (still...) working on some inherited code and am trying
to fix a bug where two JInternalFrames that contain JComponents
used as "canvases" draw on each others border's when they
overlap. Each JComponent implements it's own paintComponent()
method, which calls super.paintComponent() and then draws
itself. The two components won't draw on each other, but
if the frames overlap the lower one freely messes up any
part of the overlying frame *except* it's drawing canvas.
(Hope that all made sense, a picture would help I guess but
I've no place to put one right now)

Instead of describing this rather inefficient approach, why don't you tell
us the problem to be solved? Then someone can suggest a more reliable,
portable way to proceed.
I've found plenty of discussion on the issue various places
on the net, including SUN, but no definitive piece of example
code or clear explanation of how to fix it.

The only way I can see now if to get from the containing
JDesktopPane the locations of all objects above either
JInternalFrame and build a clipping list. This seems like
an awful lot of work, is there something simpler I'm
missing?

Like getting the effect you want with existing classes?
 
G

Guest

Paul Lutus said:
Instead of describing this rather inefficient approach, why don't you tell
us the problem to be solved? Then someone can suggest a more reliable,
portable way to proceed.

Put simply, I want to be able to paint to Graphics that are contained
in JComponents that are in turn contained in JInternalPanels that
may overlap. The JInternalPanels are contained in a JDesktopPane.

The problem is that when you write to the Graphics in an underlying
pane the result is that parts of the overlying pane get written on.
I've done enough research to understand that the cause is simple,
and pretty obvious: the Graphics is unaware that anything overlies
is, and the drawing methods themselves (paintComponent() in this
case) must manage not writing in the overlayed areas itself.

What I am asking for is some standard approach, example code, etc.
that manages this task to give me a leg up on solving it.
Like getting the effect you want with existing classes?

Well, if there is another way to get the effect of being
able to properly render dynamic graphics in two overlapping
JInternalFrames I'd like to know it.

I've been programming Swing off-and-on for some time, but
have always been doing pretty simple things. The code I'm
working with now is quite a bit more complex than I'm used
to, so I'm having to learn a lot of details I simply ignored
before. Any help would be appreciated. Existing classes
that do what I want would be nice, or examples of custom-
written classes. Or anything else for that matter...

It's strange to me that this feature of working with
overlapping JInternalFrames seems well-known, but there
are no clear example of how to do it "right", at least
that I've found so far (I'm still looking). Surely
many people must have solved it already.

--arne

DISCLAIMER: These opinions and statements are those of the author and
do not represent any views or positions of the Hewlett-Packard Co.
 
P

Paul Lutus

Put simply, I want to be able to paint to Graphics that are contained
in JComponents that are in turn contained in JInternalPanels that
may overlap. The JInternalPanels are contained in a JDesktopPane.

The problem is that when you write to the Graphics in an underlying
pane the result is that parts of the overlying pane get written on.
I've done enough research to understand that the cause is simple,
and pretty obvious: the Graphics is unaware that anything overlies
is, and the drawing methods themselves (paintComponent() in this
case) must manage not writing in the overlayed areas itself.

If you are having this problem, you must realize this doesn't happen if you
let the base classes handle the painting. Therefore (1) it might behoove
you to look into the safeguards against this sort of error in the base
classes, and (2) you may be able to imitate the behavior of the base
classes in your own code.
What I am asking for is some standard approach, example code, etc.
that manages this task to give me a leg up on solving it.

In this case, "example code" would be located in the base classes and their
ability to handle this overlap situation without drawing where they should
not draw.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top