![]() |
||||
|
| ||||
Eight Ways to Be More Productive Developing Swing Applications by Dana Nourie The room was full for this session on speeding up Java Foundation Classes/Swing (JFC/Swing) production. The speaker, Ben Galbraith, asked the audience to raise their hands to show who had experience with Swing, who was just learning, and who considered Swing a productive technology to create user interfaces (UIs). The room was evenly divided between experienced and new users, and only a few hands went up in response from those who considered Swing a productive environment in which to create UIs. Galbraith agreed that Swing technology could be difficult, but he demonstrated how to simplify this technology and make it more productive. Use a Cross-Platform Look and Feel
Developers know that creating widgets for a specific platform can reduce the number of users for their applications. And there is the problem of varying monitor sizes and different resolutions. But Swing's
See http://www.jgoodies.com/products for details. Use a GUI Builder In the recent past, graphical user interface (GUI) builders were difficult to use and did not do everything that developers needed them to. That has changed dramatically, especially in the last two years. Now, you can get great GUI builders that save a lot of time and frustration. What you can do in a few minutes in the builder would likely take you much longer to code by hand. Galbraith recommends the following IDEs:
Secondly, Galbraith recommends decoupling your applications from your GUI builder. Load the UI definition at runtime and bind behaviors to them. Dynamic and static GUI building can be mixed easily, and you can tweak a visually built GUI. This is often not the case with handwritten code, where inconsistencies and typos can have you searching line after line of code for errors. Avoid Swing's Default Layout Managers Learning all of Swing's default layout managers can take a while, and getting all your objects where you want them and the size you need them in the managers can be difficult. According to Galbraith, everything you need is in two modern layout managers:
FormLayout is a powerful, flexible and precise general-purpose layout manager. It places components in a grid of columns and rows, allowing specified components to span multiple columns or rows. GroupLayout will also be included in the final release of Java Platform, Standard Edition (Java SE) 6. Externalize Widget Styling Manually styling widgets leads to inconsistencies and can be impossible to get right. For instance, setting a font in bold in most GUI builders results in hard-coding the font family or type. Instead, consider using Cascading Style Sheets (CSS) to style Swing components. CSS can provide simple styles for your Swing fonts in much the same way as they do for the web.
For example, this is a sample of CSS:
Then use client properties to assign selectors, like this:
Or you can use Swing's
Through your code, you indicate this:
Then you apply the styles at runtime:
Employ Declarative Widget Configuration Performing common configuration on widgets can be tedious. Tables are the best example if you consider the amount of code required to center a column's contents. A declarative widget configuration system — such as DSL, XML, a properties file, or whatever else you prefer — helps dramatically. Use Binding and Validation Frameworks Getting and setting values on widgets and converting them to the appropriate type is tedious, and so is displaying meaningful error messages to the user. Binding and validation frameworks perform all of this plumbing for you.
Recommended key binding frameworks:
Enhance Swing's Event handling in Swing has a few weaknesses. Disabling components properly is tricky, and threading can be painful and tedious. Reusing event-handling logic across multiple event types is repetitious.
To overcome these annoyances and speed up production,
You can define a sensible, default event mapping for components that don't natively support actions, such as Introduce a Form Concept The act of creating and displaying a screen and handling navigation is time-consuming. Standardizing how these elements are resolved increases development speeds and productivity. Unfortunately, we ran short of time for this session, but Galbraith demonstrated that you can achieve tremendous productivity with Swing by focusing on a single look and feel, using a GUI builder and new layout managers, reducing API complexity — and the amount of code you need to write — by externalizing styling and configuration, automating binding and validation, and standardizing forms. | ||||
Comments | About
Sun | Privacy | Terms
of Use | Trademarks | Third
Party Content Disclaimer Conference content is subject to change. Copyright 1996 - 2006 Sun Microsystems, Inc. |
![]() |
|