At 11:52 PM 3/6/01 -0800, Steve Barrett wrote:
>   Swing frames and windows are AWT subclasses, so at least these should be
>as visible as their AWT counterparts.

Look at the code for them, and you'll notice not a single
line of code that draws anything on the screen (or even
in a Graphics object).  That's where this problem is
happening.

I don't understand the mechanics fully myself.  What I do
know is this:  Swing objects rely on UI classes located
in the plaf packages to actually draw themselves.  AWT
components rely on peers that are effectively front-ends
for the components used by the native platform.  That is,
Microsoft Windows has a native API (written in VC++, I
imagine) for a button; Java has a button peer API that
calls it; java.awt.Button calls the peer API.  If you
were to search through java.awt.Button and classes it
references in order to find the commands that actually
draw a button (line-drawing, rectangle-filling, etc.),
you'd never find them; you'd hit the peer API class, which
typically exists on your system in bytecode form only.
(Sun doesn't distribute the source for these classes, SFAIK.
If they did, it would probably look like a bunch of native
calls anyway.)

The fact that this native button is used is what makes
java.awt.Button what Java calls "heavyweight".  If it used
a UI class instead, it'd be "lightweight", and you would
find the actual line-drawing, etc. commands there.

For reasons I don't fully understand, components that are
drawn with native code tend to be drawn last.  (I'd have
to guess that it has something to do with the way Swing
handles repaint events, which the native code has no
knowledge of.)  Since they're drawn last, they appear to
always be on top of anything lightweight.  I made a nifty
example of this once:  A JFrame, with a JMenuBar, and a
BorderLayout in the content pane with a JLabel at north,
and a JScrollPane with a java.awt.List inside it.  When
you scroll down, the List "moves up", and happily moves
right out of the JScrollPane's area, over the JLabel, over
the JMenuBar, and then under the title bar of the JFrame,
which is heavyweight.  Other than this very odd behavior,
the interface works smoothly.

If anyone out there knows the real deal, and can correct
me on any of the above, I heartily encourage it.  No
foot-in-mouth disease for me...


_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to