17.3 Building Swing
The elegance of builders is not restricted to XML structure. Groovy provides a builder for creating Swing applications,
as well. When working with Swing, we need to perform some mundane tasks such as creating components (like buttons), registering event
handlers, and so on. Typically, to implement an event handler we write an anonymous inner class and, in the implementation handler methods, we
receive parameters (such as ActionEvent) even if we don’t care for them. SwingBuilder,
along with Groovy closures, eliminates the drudgery.
We can use the builder-provided nested or hierarchical structure to create a container (such as JFrame) and its components (such as buttons, text boxes, and so on). Initialize components ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access