Java Swing Tutorials - Herong's Tutorial Examples

Copyright © 1997-2022 Herong Yang. All rights reserved.

Java Swing Tutorials This tutorial book is a collection of notes and sample codes written by the author while he was learning Java Swing and AWT himself. Topics include Swing and AWT (Abstract Windows Toolkit) class library; graphical components: JButton, JCheckbox, JComboBox, JFrame, JLabel, JMenu, JRadioButton, JTextField; frame layouts; menus; dialog boxes; editor pane; Unicode and Chinese. Updated in 2022 (Version v4.31) with JDK 17.

Table of Contents

About This Book

JDK (Java Development Kit)

What Is JDK

Downloading and Installing JDK 15

Writing My First Java Program

Adding JDK "bin" Directory to Path Setting

JDK Documentation Installation

Introduction of Java Swing Package

What Is Swing - My First Swing Program

Graphics Environment of the Local System

java.awt.GraphicsEnvironment - Graphics Environment Class

java.awt.Toolkit - AWT Base Class

Testing Screen Resolution

JFrame - Main Frame Class

Creating Frames with Sizes and Locations

Closing Frame and Terminating Application

Listing and Interrupting AWT Threads

"AWT blocker activation interrupted" Error in JDK 1.6

JFrame Thread Behavior with JDK 8 to 12

Displaying Chinese Characters in Frame Title

Drawing Graphics - Using paint() on Frame

Drawing Graphics - Using paint() on Component

Drawing Graphics - Using paint() on Content Pane

Drawing Chinese Characters on Frames

JLabel - Swing Label Class

Creating Labels with javax.swing.JLabel Class

Creating Labels with Chinese Characters

JButton - Swing Button Class

Creating Buttons with javax.swing.JButton Class

Creating Image Buttons with javax.swing.JButton Class

Button Action Handler at the Component Level

Button Action Handler at the Frame Level

Mouse Click Handler at the Frame Level

JCheckBox - Swing Check Box Class

javax.swing.JCheckBox and Related Methods

ActionListener, ChangeListener and ItemListener

isSelected() - Getting State of Check Box

JRadioButton - Swing Radio Button Class

javax.swing.JRadioButton and Related Classes

ActionListener, ChangeListener and ItemListener

getSelection() - Getting Selected Button

JTextField - Swing Text Field Class

javax.swing.JTextField and Related Classes

ActionListener and DocumentListener

JComboBox - Swing Combo Box Class

javax.swing.JComboBox and Related Methods

ActionListener and ItemListener

getSelectedItem() - Selected Item of Combo Box

setEditable() - Use Combo Box as Text Field

Menu Bar, Menus, Menu Items and Listeners

JMenuBar, JMenu, and JMenuItem Classes - Menu Bar Test Program - Menu Test Program - Menu Item Test Program - Radio Button Menu Item Test Program - Check Box Menu Item Test Program

javax.swing.event.MenuListener - Menu Listener Interface - Menu Item Action Listener Test

Item Listener on Radio Button Menu Items

Item Listener on Check Box Menu Items

javax.swing.event.MenuKeyListener - Menu Key Listener Interface

setMnemonic() - Setting Keyboard Mnemonics on Menu Items

setAccelerator() - Setting Keyboard Accelerators on Menu Items

setMnemonic() - Setting Keyboard Mnemonics on Menus

Creating Internal Frames inside the Main Frame

javax.swing.JInternalFame - Internal Frame Class - Internal Frame Class Test

javax.swing.InternalFrameListener - Internal Frame Listener Interface

Layout of Components in a Container

LookAndFeel and UIManager

Option Dialog Boxes

JEditorPane - The Editor Pane Class

SwingWorker - The Background Task Worker

AWT (Abstract Windows Toolkit)

What Is AWT (Abstract Windows Toolkit) - My First AWT Program

Closing AWT Frame and Terminating Application

Drawing Graphics - Using paint() on Frame or Component

Creating Labels with java.awt.Label Class

Creating Buttons with java.awt.Button Class

AWT Button Action Handler at the Component Level

AWT Button Action Handler at the Frame Level

AWT Button Mouse Click Handler at the Frame Level

AWT TextField and ActionListener - AWT Menu Bar Test Program - AWT Menu Test Program - AWT Menu Item Test Program - AWT Menu Item Action Listener

Integration with Desktop System

javax.awt.Desktop and Related Methods

browse() - Launch Default Web Browser

mail() - Launch Default Email Program

edit() - Launch Default Editor for Given File

Archived Tutorials

Archived: Downloading and Installing JDK 12

Archived: Downloading and Installing JDK 10


Full Version in PDF/EPUB

Keywords: Swing, AWT, Java, Graphics, User Interface