Chapter 10. Swing Dialogs


In most applications, information occasionally needs to be displayed for a brief period of time, often just long enough for the user to read it and click OK or perhaps enter a value, such as a password. Swing provides the JOptionPane class to make creating such simple dialog boxes extremely easy in many cases requiring just one line of code.

Applications may also serve more complex dialog needs, such as providing a property editor in which a set of related values can be modified, with an appropriate interface. Swing's JDialog class supports such general-purpose dialogs. JDialogs can also be non-modal,[1] which means the user does not need to close the dialog before interacting with other application windows. When possible, implementing such an interface yields a more pleasant and productive user experience.

[1] A modal dialog forces the user to interact only with that dialog until it is dismissed.

Even though JOptionPane makes it very easy (for the programmer) to pop up a dialog, bear in mind that this will disrupt the flow of activity for users and force them to deal with the dialog before they can proceed with their underlying task. While this is sometimes unavoidable or even appropriate, it is usually worth trying to find less disruptive alternatives (direct manipulation, a non-modal floating notification, or some other non-modal approach). This may require more work on the part of the developer but will result in a better application. And if the application is widely adopted, the benefits are multiplied across the entire user base.



Java Swing
Graphic Java 2: Mastering the Jfc, By Geary, 3Rd Edition, Volume 2: Swing
ISBN: 0130796670
EAN: 2147483647
Year: 2001
Pages: 289
Authors: David Geary

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net