Skip to Main Content
Java Swing, 2nd Edition
book

Java Swing, 2nd Edition

by Dave Wood, Robert Eckstein, Marc Loy, James Elliott, Brian Cole
November 2002
Intermediate to advanced content levelIntermediate to advanced
1278 pages
38h 26m
English
O'Reilly Media, Inc.
Content preview from Java Swing, 2nd Edition

Working with Focus

Prior to SDK 1.4, focus issues in Java were complicated and not adequately implemented. The problems were deeper than bugs in the code—of which there were certainly plenty, many due to inconsistencies between platforms. The design itself was fundamentally flawed.[1]

Because of these deep changes, the “right way” to do things now differs substantially from previous versions of Java. To avoid confusion, we discuss only the focus model introduced in 1.4. Developers who work with earlier releases should refer to the book’s web site (http://www.oreilly.com/catalog/jswing2) for the first edition’s version of this section.

Here are some highlights of changes in the focus system in 1.4:

  • FocusManager has been deprecated and replaced by KeyboardFocusManager.

  • It’s now possible to learn which component currently has the focus.

  • Lightweight children of Window (not just Frame or Dialog) are able to receive keyboard input.

  • When focus changes, the component gaining focus can find out which one lost it, and vice versa.

  • There is far less platform-dependent code; it has been replaced by a very extensible public API in AWT, with many levels where custom logic can be plugged in. Heavyweight and lightweight focus is much better integrated.

  • Components can lose focus temporarily (e.g., to a scrollbar).

  • It’s a lot easier to work with.

The net result of all these changes is that the system tends to work the way you want it to, and even when you want to add fancy new features, doing so requires less ...

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.
Start your free trial

You might also like

Java Threads, 3rd Edition

Java Threads, 3rd Edition

Scott Oaks, Henry Wong

Publisher Resources

ISBN: 0596004087Errata PageSupplemental Content