http://developer.java.sun.com/developer/qow/archive/75/index.html Topic:   What is a "Peer"?
 Question:
Hello, I could find little documentation about the Peer classes(?) in Java,
even in big books it is hardly mentioned. Can anyone tell me a bit more abou
t it or maybe a link to useful information about it? Thanks Francesco
Answer:
From Moovels:
I'm not exactly sure what Peer objects are for, but I believe that they are
a way to access heavyweight operating system dependent components. A heavywe
ight component being an operating system's own default components. For examp
le, an AWT component like a button on a Windows system is different than it
is on a Mac System or an OS/2 System. I think the peer components are for ac
cessing the operating system's button (or menu, or textfield, or whatever co
mponent is in question) methods. I don't think that there is any real reason
 for a programmer to actually access peer classes directly, unless they were
 reprogramming AWT components such as button for some reason. Hope that help
ed answer your question.
ed answer your question.
From sudharsan:
Moovels is correct. In normal course, one does not need to use a peer of any
 component. A "peer" component is an OS specific implementation of a compone
nt on the Java platform. That is the reason with AWT a component (like a fra
me) looks like the one on the current OS the JavaTM Virtual Machine1 is runn
ing on. When you try to close the frame (window) for example, the Frame comp
onent delegates (passes on) the event to the OS-specific component (the wind
ow). This ensures the correct OS-specific behavior of all components.
Now, with Swing, the advantage is not having an OS specific look and feel (a
nd consequently behavior). That means, there need not be aN OS equivalent of
 any Swing component. Imagine Swing components to be drawings on a OS-specif
ic window. You can draw anything you want.
All said and done, I found the article on Swing connection that I mentioned
the first time. Mixing Heavy and Light Components
Best of luck! Happy Swinging.
Many thanks to JDC members Moovels, Marchioni , and sudharsan for contributi
ng to this answer.
Note: If you have a question to which you need an answer, try the JDC Forums
. You can read through the existing topics, or with your free JDC membership
, you can post new messages or threads.
----------------------------------------------------------------------------
----
----
Mon Feb 14 22:08:30 PST 2000
gvsbhaskar
Adding to what Moovels and Sudarshan has said about peers, these peers are d
esigned to get the look and feel of the underlying OS visual components. The
se peers are system dependent and they are the ones which interact with the
system and attain platforn independency.
Tue Feb 15 01:42:04 PST 2000
[Member not logged in]
Peers make components(button,checkbox, Text Area and such) look the same as
users expect from the OS. Users want to see a GUI with which they are fimila
r.
Tue Feb 15 01:55:58 PST 2000
[Member not logged in]
kumar here,
AWT components are using the OS's components to draw itself. But Swing Compo
nents do not depend on an operating system's components. Am I right? Please
mail me at : [email protected]
Tue Feb 15 11:25:47 PST 2000
[Member not logged in]
The peers is one of the application of design pattern: Abstract Factory. The
 peers are usually created by the class java.awt.ToolKit. For more detail in
formation, please refer to the book: Oatters In Java, Volumn 1. The author i
formation, please refer to the book: Oatters In Java, Volumn 1. The author i
s Mark Grand.
Tue Feb 15 16:08:09 PST 2000
hemant_jal
Hi Sudarshan,
I am confused. You mean if using Swing we cannot have local OS specific look
 and feel?
Wed Feb 16 04:28:05 PST 2000
Anonymous
Sudharsan is correct. He has explained the question exactly.
Wed Feb 16 12:37:12 PST 2000
Anonymous
Got a good explaination on "Peer." Thanks to all who replied. Thu Feb 17 07:
47:53 PST 2000
[Member not logged in]
Sudarshan and moovels are right. The peer components are heavy weight compon
ents, which are OS specific. So they depend on the drawing capabilities of t
he particular OS. But when Swing is considered all the required components f
or GUI building, are built into the Java system. So this makes you feel the
GUI is the same on all platforms. I think there should be some overhead usin
g Swing components, instead of a peer, but I am not sure of it though.
"THE INFORMATION PROVIDED IN THE JAVA DEVELOPER'S CONNECTION IS PROVIDED "AS
 IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITH
 IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITH
OUT LIMITATION THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR,
AND NON-INFRINGEMENT.
THIS INFORMATION IS PROVIDED AT NO CHARGE. BY USE OF THE INFORMATION YOU AGR
EE THAT NEITHER SUN MICROSYSTEMS, INC. NOR ITS LICENSORS WILL BE LIABLE FOR
ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL
, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF SUN OR ITS LICENSORS
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALL
OW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL
DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
THIS INFORMATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERROR
S. CHANGES ARE PERIODICALLY ADDED TO THE INFORMATION HEREIN. SUN MICROSYSTEM
S, INC. MAY MAKE IMPROVEMENTS AND OTHER CHANGES IN THE PRODUCTS AND THE PROG
RAMS DESCRIBED HEREIN AT ANY TIME WITHOUT NOTICE."