Java Foundation Classes in a Nutshell

Java Foundation Classes in a Nutshell

5.0 1
by David Flanagan, Paula Ferguson
     
 

View All Available Formats & Editions

Java Foundation Classes in a Nutshell is an indispensable quick reference for Java programmers who are writing applications that use graphics or graphical user interfaces. The author of the bestsellingJava in a Nutshell has written fast-paced introductions to the Java APIs that comprise the Java Foundation Classes (JFC), such as the Swing GUI

Overview

Java Foundation Classes in a Nutshell is an indispensable quick reference for Java programmers who are writing applications that use graphics or graphical user interfaces. The author of the bestsellingJava in a Nutshell has written fast-paced introductions to the Java APIs that comprise the Java Foundation Classes (JFC), such as the Swing GUI components and Java 2D, so that you can start using these exciting new technologies right away.This book also includes O'Reilly's classic-style, quick-reference material for all of the classes in the javax.swing and java.awt packages and their numerous subpackages. This reference material covers all of the new JFC classes in the Java 2 platform, as well as the existing Java 1.1 AWT classes. Once you've learned about the JFC, you'll keep this book next to your keyboard for handy reference while you program.Java Foundation Classes in a Nutshell contains the following:

  • An overview of the architecture of graphical user interfaces built with both the new Swing API and the older AWT
  • An introduction to the important components and application services provided by the Swing API
  • An comprehensive explanation of the features of the new Java 2D graphics API
  • A complete quick reference for the graphics- and GUI-related classes in the Java 2 platform
This book is part of the two-volume set of quick references that every Java programmer needs. It is an essential companion to Java in a Nutshell, 3rd Edition, which covers the key nongraphical APIs in Java 1.2. A third volume, Java Enterprise in a Nutshell, focuses on the Java Enterprise APIs and is of interest to programmers working on server-side or enterprise Java applications.

Product Details

ISBN-13:
9781565924888
Publisher:
O'Reilly Media, Incorporated
Publication date:
10/28/1999
Series:
In a Nutshell (O'Reilly) Series
Pages:
754
Product dimensions:
6.03(w) x 9.02(h) x 1.56(d)

Read an Excerpt


Chapter 3: Swing Programming Topics

3.1 Versions of Swing

http://java.sun.com/products/jfc/. As this book goes to press, the most recent version of Swing is Swing 1.1.1. This version of Swing is bundled with Java 1.2.2 and is also available for use with Java 1.1 from the web site mentioned in the previous paragraph. Swing 1.1.1 fixes many bugs in the initial release of Swing 1.1 but does not change the Swing 1.1 API in any way. Its use is strongly recommended. Swing 1.1.1 is the last release of Swing that will be available for use with Java 1.1.

Development of Swing continues, and Java 1.3 will ship with a new version that includes a number of minor changes and improvements to the Swing API. This future release will focus on improving the existing APIs and should not add many new APIs.

3.2 Labels and HTML

In the initial releases of Swing 1.1 and Java 1.2, the JLabel, JButton, and related classes that display textual labels can display only a single line of text using a single font. In Swing 1.1.1 and Java 1.2.2, however, components like these can display multiline, multifont text using simple HTML formatting. To display formatted text, simply specify a string of HTML text that begins with an <HTML> tag. You can use this feature to present text using multiple fonts, font styles, and colors. Just as important, however, the introduction of HTML allows you to specify multiline labels.

This new formatted text display feature is available in Java 1.2.2 for the JLabel, JButton, MenuItem, JMenu, JCheckBoxMenuItem, JRadioButtonMenuItem, JTabbedPane, and JToolTip classes. It is not supported (at least in Java 1.2.2) by JCheckBox or JRadioButton, however. Formatted text display is particularly useful with JOptionPane dialog boxes (described later in this chapter), as they display text using internal JLabel objects.

3.3 Actions

javax.swing.Action interface Action interface ActionListener interface, so it actionPerformed() method. It is this Action object also has an arbitrary set of Action object has an enabled setEnabled() method that allows "Cut" Action object directly to a JMenu or JToolBar JMenuItem or JButton to JMenuItem or JButton JMenuBar or JToolBar to JMenuBar and JToolBar display an action's textual name and its Action interface helps you Action objects directly. Since Action is a kind of ActionListener, you must define an individual Action that implements the actionPerformed() method for each of your AbstractAction class is actionPerformed() method.

3.4 Tooltips

tooltip: setToolTipText() method. This toolTipText property is inherited from JComponent, so it is shared by all Swing enabled ToolTipManager object. The

 ToolTipManager.sharedInstance().setEnabled(false);

3.5 Timers

javax.swing.Timer object generates single ActionEvent events at time Timer Timer object that Timer. Timer objects just like regular Timer has addActionListener() method that you can use initialDelay property specifies how many Timer waits before firing its first ActionEvent. If the repeats true, Timer generates a new ActionEvent each time delay milliseconds passes. delay coalesce true, Timer combines ActionEvent, rather than letting a queue of

3.6 The Event Dispatch Thread

SwingUtilities.invokeLater() and SwingUtilities.invokeAndWait(). You pass a Runnable object to each method, and the run() method of this object is invokeLater() run() invokeAndWait() does run() method has completed. invokeLater() and invokeAndWait() methods do not run Runnable object right away. Instead, each Runnable object Runnable object is extracted from the event run() method. This means that invokeLater() provides a useful way to defer the

3.7 Client Properties

JComponent includes a hashtable in which it can putClientProperty() and getClientProperty() methods. Since these are JComponent methods, they are inherited by all String object. JMenu JMenuItem components. Each ActionListener setActionCommand() method (inherited from AbstractButton) to associate a string with each JMenuItem components. Then the action String in order to decide how to JMenuItem.

"JInternalFrame.isPalette"

JInternalFrame is being used as a Boolean.TRUE to change the look of the "JScrollBar.isFreeStanding"

JScrollPane sets this client property Boolean.FALSE on the JScrollBar components it creates. "JSlider.isFilled"

JSlider Boolean.TRUE causes the slider to "JToolBar.isRollover"

Boolean.TRUE on a JToolBar causes the component "JTree.lineStyle"

JTree component draws the branches of its

3.8 Keyboard Shortcuts

JButton is KeyEvent that tells Spacebar or the Enter key. Similarly, JMenu and JList respond to

3.8.1 Focus Management

"window," Tab key to Tab, Swing moves the keyboard focus from JLabel objects, do Shift-Tab, nextFocusableComponent property of your isFocusCycleRoot(). If this method returns true, the container defines a focus Ctrl-Tab to traverse to the next focus Ctrl-Shift-Tab to setFocusCycleRoot() method: the only way you isFocusCycleRoot() method. JTextArea and JEditorPane Tab key for their own Ctrl-Tab to requestFocus() method of that component. requestFocus() requestFocus() calls, set its requestFocusEnabled property to false. For example, you might set this JButton so that the user can javax.swing.FocusManager object. You can FocusManager.getCurrentFocusManager(). If FocusManager.setCurrentFocusManager(). ...

Meet the Author

David Flanagan is a computer programmer who spends most of his time writing about JavaScript and Java. His books with O'Reilly include Java in a Nutshell, Java Examples in a Nutshell, Java Foundation Classes in a Nutshell, JavaScript: The Definitive Guide, and JavaScript Pocket Reference. David has a degree in computer science and engineering from the Massachusetts Institute of Technology. He lives with his wife and son in the U.S. Pacific Northwest bewteen the cities of Seattle, Washington and Vancouver, British Columbia. David has a simple website at http://www.davidflanagan.com.

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >

Java Foundation Classes in a Nutshell 5 out of 5 based on 0 ratings. 1 reviews.
Guest More than 1 year ago
This is a must have quick reference.