awt java layout-manager listener swing

Swing GUI listeners without AWT


I am a starting Java developer, learning just from internet tutorials. I am learning full-screen GUI applications. I was told yesterday that I shouldn’t use AWT in my programs because it is outdated. I already know about light and heavyweight components, the main problem is the mouse and keyboard listeners.
Why is AWT outdated?

How to make a program without AWT (adding listeners to a JComponent etc)? What kind of Swing things can replace the AWT?


  • I have never heard of listeners other than AWT. Would be nice to know it myself.

    – Pangolin

    Jun 6, 2011 at 16:37

  • 3

    @Nideo: Feast your ‘ears’ on the 20+ listeners in the javax.swing.event package. 😉

    Jun 6, 2011 at 17:15


You’re mis-interpreting the information given to you. You should avoid using Swing components with AWT components. It’s OK to use Swing with the AWT listener structure, layout managers, etc. and in fact it’s impossible not to.



    There have been some good answers, but I would like to cover a slightly different aspect. Things that Swing provides beyond AWT.


    Swing supports styled documents in JEditorPane & JTextPane & to a limited extent using HTML in some other JComponents. AWT does not support styled documents in any component.

    AWT provides no tree based structure like JTree, no tabular structure such as JTable, no version of JToolBar.

    AWT has no equivalent (that I can find or recall) for JColorChooser & none for the simple utility class – JOptionPane.


    As mentioned in a comment, see the 20+ extra/alternate listeners in the javax.swing.event package.

    Pluggable Look & Feel

    Swing components can be set to a particular look & feel at run-time, including a native PLAF.

    See the screen shots on the Nested Layout Example for some more samples.


    In addition to the plethora of AWT layouts, Swing provides:

    1. BoxLayout
    2. GroupLayout
    3. OverlayLayout
    4. ScrollPaneLayout
    5. SpringLayout
    6. ViewportLayout


    There is probably a lot more I missed in that brief description, but the bottom line is that Swing is an altogether newer and more enabled GUI toolkit.

    Swing both builds on, and relies heavily on, classes in the AWT.



      Java’s Swing takes ActionListeners, which are part of the AWT package. If you wish to use swing, you must use some form of an AWT ActionListener. That is just the way things are. I don’t suggest using Java at all for complex guis, but nor would I say that AWT is outdated, as there is no direct replacement. Thus, just go ahead and use AWT.

      As an alternative, you could look into JOGL, but that’s more if you are trying to create something game-oriented.