Swing and AWT Mixing is bad, but still done, why?
awt, event-listener, import, java, swing
Solution
Swing shares quite a few classes with AWT, and uses some of the same implementation - note that javax.swing.JComponent (the base Swing component class) actually inherits from java.awt.Component (the base AWT container class)
It's actually not that much of a problem to mix Swing and AWT if you are careful. The main pitfalls are:
- You risk getting a very different look and feel if you mix AWT and Swing UI components
- Swing components are "lightweight" (rendered by Java) while AWT components are "heavyweight" (implemented as components in the host platform) - this means you will have problems if you put AWT components inside Swing components (the other way round is fine)
Problem
I have noticed that people recommend not intermixing Swing and AWT `Components`, however we see this alot: ``` import javax.swing.AbstractButton; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.ImageIcon; //AWT imports though only for listeners import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; ``` So why do many including Java (because I got that off their tutorial here) still use AWT imports, though I see its mainly for `Listener`s. How do you add native Swing `Listener`s/Libraries for stuff like `Key`, `Button`, `JComboBox` presses/slections etc? Or would I use `firePropertyChangeListeners()`? (though that relates to Java Beans) It has been confusing me now for some time, most of my app have Swing and AWT which is said to be bad?