Preface

Java > Core SWING advanced programming > Preface

 

There is no doubt that, in the two years or so since the first production version of Swing was released, it has gradually taken over from the Abstract Window Toolkit (AWT) as the preferred graphical component set for client-side Java applications. With this increase in reliance on Swing has come a greater demand for development staff who are familiar with its intricacies and who know how to go beyond the obvious and get the best out of the powerful components that Swing contains. The Swing application programming interface (API) is huge, but that's not the worst problem for commercial developers. The issue is not so much that there is a very broad API the real problem is that much of what you can do is hidden away under the covers and not very clearly outlined in the documentation that Sun provides. What's more, the Swing toolkit has a relatively low-level API and, although the components make very good building blocks, in real-world applications you need to enhance them to make them fully usable. Take, for example, the text components. On the face of it, they are relatively simple to use and give you a lot features in the basic API. But what if you want an input field that only accepts numbers? What about limiting the number of characters that the user can type into the field, or forcing letters to uppercase even if the user types them in lowercase? You won't find these features documented in the API, but the text components are built around a framework that makes it possible to plug in these enhancements, provided you know what you are doing. This book aims to show you some of the techniques you can use to make best use of Swing.

Because Swing is such a large topic, authors can take one of two approaches when writing about it. One possibility is to try to cover the whole API in a single book. This leads either to something very large (and probably overwhelming for most readers) or to something that is smaller, but broad and shallow and therefore risks not giving the reader enough information on anything. The alternative is to address only the most important parts of the API, the ones that most developers will use most of the time, but to cover it in enough detail that the reader can find exactly what he/she needs. It would also have to contain enough background to allow the reader to work out extra details from the source code. The latter approach is the one that I adopted in Core Java Foundation Classes, one of the first Swing books published. In trying to keep the number of pages down to something manageable, I had to leave out of Core Java Foundation Classes some of the more esoteric parts of the Swing API, such as the Undo package, in order to be able to give full coverage to the basics of the architecture and to the more sophisticated components, JTable and JTree, which were completely new to AWT developers.

Core Swing: Advanced Programming picks up where Core Java Foundation Classes left off, both expanding on some of the areas already covered in some detail in the first book and also introducing areas that Core Java Foundation Classes could not address. For example, even though Core Java Foundation Classes covered the text components far more thoroughly than most of the other Swing books available at the time (and since), there still remained a lot to say about them. This book tells you everything you need to know to build the enhanced text fields that you need in order to create a professional, commercial user interface and much more. In the first chapter, for example, you'll see how to create a text field that only accepts valid numbers, where the allowed input format is specified as a property of the component and how to perform other checks or transformations on the text that the user types.

To ensure their relevance to the problems being faced by real-world developers, many of the examples and topic areas covered in this book were chosen because they are frequently discussed on the Java GUI-related Internet news groups. If, like many contributors to the comp.lang.java.gui news-group, you've looked at Swings HTML support and wanted to make full use of it but been daunted by its complexity (and the fact that it isn't documented anywhere), you'll need to read Chapter 4, which contains 200 pages almost entirely dedicated to this single topic, while Chapter 8 shows you how to make use of the Java 2 drag-and-drop feature, together with Swing components, to enhance the usability of your application's user interface. The central example of this chapter shows you how to add drag-and-drop features to a JTree that gives a visual representation of a file system, thus allowing you to create a basic Windows Explorer-type application with only a few lines of code. You'll also find detailed coverage of the Undo package and two chapters that show you exactly how to make the best use of the rendering and editing facilities of JTable.

 

 



Core Swing
Core Swing: Advanced Programming
ISBN: 0130832928
EAN: 2147483647
Year: 1999
Pages: 55
Authors: Kim Topley

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