Swing
Swing
Home
The e-book has 621 pages and 206 code examples. The e-book goes quickly to the point and is loaded
with practical examples which focus on one important aspect. Heavy emphasis is placed on clarity and
conciseness. No time is wasted with unimportant digressions. It is an ideal material for those who
already know some basics of Java Swing. The e-book is written in plain English.
The code examples were tested on Linux and Windows. They can be run on JDK 7 and JDK 8. After
purchasing the e-book, you will obtain a ZIP file. In the ZIP file, you will find a PDF file and all code
examples. The code examples are in the form of NetBeans projects.
Once you make a payment, you will also get a confirmation email from Paypal. If something goes wrong
with the payment process, drop me an email at vronskij(at)gmail.com.
Price
This is Advanced Java Swing e-book. This e-book covers advanced parts of the Swing in a great detail.
The complete table of contents is listed at the end of the page.
1. Foundations
1.1 Toplevel containers
1.2 Events
1.3 SwingWorker
1.4 Painting
1.5 BufferedImage
1.6 Miscellaneous
2. Layout management
2.1 GroupLayout
2.2 MigLayout
3. Advanced components
3.1 JList
3.2 JTable
zetcode.com/ebooks/advancedjavaswing/ 1/12
3/25/2020 Advanced Swing e-book
3.3 JTree
3.4 Text components
The Foundations part explains six different areas of Swing. The first chapter of the e-book covers Swing
toplevel containers—fundamental components which contain other Swing components. The Events
chapter is an in-depth coverage of the event handling system of Swing. It has 25 examples. The
SwingWorker chapter explains the very important SwingWorker class and provides three detailed
examples. The Painting chapter explains the basics of the painting mechanism. In the BufferedImage
chapter, we show how to work with images in Swing. In the Miscellaneous chapter, we cover various
aspects of Swing, including keyboard handling, compound border, and making a screenshot.
The Layout management part explains the layout management of Swing components. This area is
considered to be one of the most difficult areas of GUI programming. Therefore, the e-book gives
particular emphasis on the layout management process. There are two chapters: GroupLayout manager
and MigLayout manager. These are the most flexible layout managers available for Swing. The chapters
contain many easy to understand practical examples. (GroupLayout 18 examples, MigLayout 41 examples.)
The Advanced components part covers advanced Swing components in a great detail. Plenty of practica
examples explain the JList (14 examples), the JTree (22 examples), the JTable (29 examples), and severa
text components (28 examples).
Screenshots
Here you can see some of the screenshots from the e-book.
zetcode.com/ebooks/advancedjavaswing/ 2/12
3/25/2020 Advanced Swing e-book
Figure: Explaining horizontal and vertical alignments with the MigLayout manager.
zetcode.com/ebooks/advancedjavaswing/ 3/12
3/25/2020 Advanced Swing e-book
Figure: Demonstrating the colour palette of the Metal look and feel with the UIManager.
zetcode.com/ebooks/advancedjavaswing/ 4/12
3/25/2020 Advanced Swing e-book
zetcode.com/ebooks/advancedjavaswing/ 5/12
3/25/2020 Advanced Swing e-book
Table of Contents
1. Preface
3. Foundations
3.1 Toplevel containers
3.1.1 JFrame
3.1.2 JLayeredPane
3.1.3 Glass pane
3.1.4 JDialog
3.1.5 JWindow
3.2 Events
3.2.1 Multiple listeners
3.2.2 Multiple sources
3.2.3 EventHandler
3.2.4 Custom event
3.2.5 Observer pattern
3.2.6 Actions
3.2.6.1 Action example
3.2.6.2 Toggle buttons
3.2.7 ActionListener vs ItemListener
3.2.8 Application closing
3.2.9 EventQueue
3.2.10 AWTEventListener
3.2.11 MouseEvent
zetcode.com/ebooks/advancedjavaswing/ 6/12
3/25/2020 Advanced Swing e-book
3.2.11.1 MouseListener
3.2.11.2 Mouse event types
3.2.11.3 MouseAdapter
3.2.12 ItemEvent
3.2.13 PaintEvent
3.2.14 FocusEvent
3.2.14.1 Selecting all text on gaining focus
3.2.14.2 Initial focus
3.2.15 Scheduling tasks
3.2.15.1 Swing timer
3.2.15.2 Utility timer
3.2.15.3 Executor service
3.3 SwingWorker
3.3.1 SplashScreen
3.3.2 Searching images
3.3.3 Supervisor worker
3.4 Painting
3.4.1 The paintComponent() method
3.4.2 Custom icon
3.4.3 Painting into image
3.4.3.1 Grayscale image
3.4.3.2 Component capture
3.4.4 The repaint() method
3.4.4.1 Points
3.4.4.2 Moving circle
3.5 BufferedImage
3.5.1 Grayscale image
3.5.2 Scaling an image
3.5.3 Spotlight
3.5.4 Sun and cloud
3.5.5 Subimage
3.6 Miscellaneous
3.6.1 Keyboard
3.6.1.1 KeyListener
3.6.1.2 Key bindings
3.6.1.3 Mnemonics and accelerators
3.6.2 UIManager
3.6.2.1 Selecting laf
3.6.2.2 Colour palette
3.6.3 Compound border
3.6.4 Custom border
3.6.5 Screen capture
3.6.6 Opaque
3.6.6.1 Difference in meaning
zetcode.com/ebooks/advancedjavaswing/ 7/12
3/25/2020 Advanced Swing e-book
4. Layout management
4.1 GroupLayout manager
4.1.1 First examples
4.1.1.1 Simple example
4.1.1.2 Simple example 2
4.1.2 Independent dimensions
4.1.2.1 Grid of buttons
4.1.2.2 Grid of buttons 2
4.1.3 Gaps
4.1.3.1 Fixed gaps
4.1.3.2 Automatic gaps
4.1.3.3 Resizable gaps
4.1.4 Indent
4.1.5 Alignments
4.1.5.1 Horizontal alignment
4.1.5.2 Vertical alignment
4.1.5.3 Baseline alignment
4.1.6 Parallel group's size
4.1.7 Practical examples
4.1.7.1 Corner buttons
4.1.7.2 Password
4.1.7.3 Windows
4.1.7.4 Review
4.1.7.5 Go To Class
4.1.7.6 Tags
4.2 MigLayout manager
4.2.1 Grid
4.2.1.1 Cells
4.2.1.2 Horizontal flow mode
4.2.1.3 Vertical flow mode
4.2.1.4 Flow mode in a cell
4.2.1.5 Orientation
4.2.1.6 No grid
4.2.2 Bound size
4.2.2.1 Component size
4.2.2.2 Component size 2
4.2.2.3 Gap size
4.2.3 Constraints
4.2.3.1 Units
4.2.3.2 Insets
4.2.3.3 Absolute positioning
4.2.3.4 Relative positioning
zetcode.com/ebooks/advancedjavaswing/ 8/12
3/25/2020 Advanced Swing e-book
5. Advanced components
5.1 JList component
5.1.1 Simple examples
5.1.2 List orientation
5.1.3 DefaultListModel
5.1.3.1 Read-only data
5.1.3.2 Modifying data
5.1.4 AbstractListModel
5.1.4.1 Read-only data
5.1.4.2 Modifying data
5.1.5 ListDataListener
5.1.6 Selections
5.1.7 Renderers
5.1.7.1 Rendering stripped background
zetcode.com/ebooks/advancedjavaswing/ 9/12
3/25/2020 Advanced Swing e-book
6. Bibliography
zetcode.com/ebooks/advancedjavaswing/ 12/12