Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures


Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips


Submit News
Search the site here...
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Mixing Heavy and Liight components

JavaFAQ Home » Swing, AWT Go to all tips in Swing, AWT

Bookmark and Share

Although the Swing component set provides alternatives to using pre-Swing AWT components (such as Button, List, and the like), one of the primary design goals for Swing was that it be based on AWT architecture.

A significant benefit of such layering is that it greatly facilitates porting AWT-component programs to Swing. In fact, because both the AWT and Swing component sets use the same AWT infrastructure, it's possible to mix both kinds of components in the same program -- a technique that allows for phased migration of applications.

This article will lay out the rules for mixing components, and will provide some information and guidelines that we hope will make the mixing of AWT and Swing components as painless as possible.

Heavy and light components

Most of the issues related to mixing AWT and Swing components are related to the mixing of so-called heavyweight and lightweight components. A heavyweight component is one that is associated with its own native screen resource (commonly known as a peer). A lightweight component is one that "borrows" the screen resource of an ancestor (which means it has no native resource of its own -- so it's "lighter").

(Lightweight component support was introduced in JDK1.1, and you can read more about it in the JDK1.1 Lightweight UI Framework design document.)

We generally don't recommend mixing Swing and AWT components because there are significant benefits in sticking with programs that are written entirely in Swing (and thus use only lightweight components).

Some of the benefits of using Swing components are:

  • More efficient use of resources: Lightweight components are really "lighter" than heavyweight components.
  • More consistency across platforms because Swing is written entirely in Java.
  • Cleaner look-and-feel integration: You can give a set of components a matching look-and-feel by implementing them using Swing.

Despite the benefits of using Swing components exclusively, a developer may sometimes have to mix AWT components and Swing components in the same program (even when migration is not to blame). For example, such mixing may be required when a Swing version of a particular AWT component is not yet available.

Because there's sometimes no alternative to mixing heavyweight and lightweight components, we have provided a few options in Swing to make a certain level of component-mixing possible. However, as anyone who has tried this approach knows, there are some practical limitations to this approach.

Full article is here

P.S. (after the article was written info) It will be possible soon to mix AWT and Swing... How? Read it next Monday Smile

 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search

Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy