What is a lightweight component?
Created Apr 20, 2000
Before talking about lightweight components, it is necessary to discuss the concept of Java peers. When instantiating any of the AWT component classes, e.g. a java.awt.Button, the system actually asks the native environment to create the component. This ensures the user sees the native look-and-feel and the component acts like the native control. The native code that provides this look-and-feel is called a peer; each platform has its own set of peers. A Java button appears and acts as a Windows button when run under Windows, as a Macintosh button when run under Macintosh, and as a Unix button when run under Unix. The FAQ found at http://www.jguru.com/jguru/faq/view.jsp?EID=11353 discusses the concept of peers in more detail.
While in practice this sounds great, there are problems because not all native controls respond similarly to the same events. This can result in a Java program exhibiting different behavior under different Java AWT environments. To overcome this problem, you must use components written entirely in Java. That is, components that do not have a native peer. These are called lightweight components. Swing provides a set of pure Java lightweight components, ensuring better cross-platform compatibility. (Or at least ensuring that any bugs are the same bugs on all platform - a very important feature!)