|
Average Rating: 4.7/5 | Rate this item | 3 users have rated this item.
|
Expertise: Intermediate
Language: Java
June 4, 2001
Why You Shouldn’t Mix AWT and Swing
There are fundamental incompatibilities between the ways AWT and Swing draw themselves. Swing classes are pure Java classes that look the same on all operating systems. AWT Java classes are not pure Java classes. They use underlying C/C++ native code (OS dependent) that can cause different appearances in different operating systems, so mixing Swing and AWT defeats the purpose of Swing.
There are no big architectural differences; the class hierarchy is almost the same. The difference lies in the way the two are drawn on the screen. AWT components are heavyweight components with their own viewports, which send output to the screen. Swings are lightweight components and do not write themselves to the screen, but instead redirect the screen to the components it builds on. Heavyweight components have their own Z-ordering. This is the reason why Swing and AWT cannot be combined in a single container. If they are, the AWT components will be drawn on TOP of Swing components.
For example: When AWT components are used with JtabbedPane, they do not disappear when the tabs are switched.
Nitin Garg
If you have a hot tip and we publish it, we'll pay you. However, due to accounting overhead we no longer pay $10 for a single tip submission. You must accumulate 10 acceptable tips to receive payment. Be sure to include a clear explanation of what the technique does and why it's useful. If it includes code, limit it to 20 lines if possible. Submit your tip here.
|