28.12.2012 Views

Core JFC Java Foundation Classes 2nd edition - Read

Core JFC Java Foundation Classes 2nd edition - Read

Core JFC Java Foundation Classes 2nd edition - Read

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

This chapter looks at several Swing mechanisms that you can use to build<br />

better applications. The main theme of the first half of the chapter is<br />

the need to be able to operate the application without using a mouse.<br />

This is often a difficult area for some software developers to get right because<br />

they rarely use the keyboard to navigate around an application, but to the<br />

expert user the ability to get quickly to the parts of the application that they use<br />

the most is of great importance. Getting to a piece of the application quickly<br />

usually means using accelerator keys or shifting the input focus manually with<br />

the Tab key until a particular control is reached. This chapter looks at the basic<br />

mechanisms that the Swing focus manager offers and shows how much simpler<br />

it is to create key accelerators with Swing than it was with the AWT.<br />

The use of keyboard accelerators leads naturally to the concept of<br />

Actions, which encapsulate application functionality in a way that is independent<br />

of the manner in which it is accessed. This chapter looks at using<br />

Actions as targets for accelerator keys, but later you'll see that they can be<br />

used with menus and toolbars as well.<br />

The second half of the chapter looks at the powerful Swing scrolling components,<br />

JScrollPane and JScrollBar. JScrollPane is much more useful<br />

than its AWT counterpart (ScrollPane). You'll see how to arrange for a<br />

component to be scrolled and how to customize the appearance and operation<br />

of JScrollPane. Finally, the two halves of the chapter are brought<br />

together by an example that shows how you can arrange for the user to be<br />

able to scroll a view using only the keyboard.<br />

453

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!