Java Sun and JLF home page   Previous Next Contents/Index/Search

6: Behavior

Users interact with the computer via the mouse, the keyboard, and the screen. Such interaction is the "feel" portion of the Java look and feel. This chapter provides input guidelines and recommendations for interaction techniques. It describes mouse operations, including information on pointers, and drag-and-drop operations. It also discusses keyboard operations, including the use of mnemonics, keyboard shortcuts, and keyboard focus in Java look and feel applications.

 

 

Mouse Operations

In Java look and feel applications, the following common mouse operations are available to users:

 

  • Moving the mouse changes the position of the onscreen pointer (often called the "cursor").
  • Clicking (pressing and releasing a mouse button) selects or activates the object beneath the pointer. The object is usually highlighted when the mouse button is pressed and then selected or activated when the mouse button is released. For example, a click is used to activate a command button, to select an item from a list, or to set an insertion point in a text area.
  • Double-clicking (clicking a mouse button twice in rapid succession without moving the mouse) is used to select larger units (for example, to select a word in a text field) or to select and open an object.
  • Triple-clicking (clicking a mouse button three times in rapid succession without moving the mouse) is used to select even larger units (for instance, to select an entire line in a text field).
  • Dragging (pressing a mouse button, moving the mouse, and releasing the mouse button) is used to select a range of objects, to choose items from drop-down menus, or to move objects in the interface.

 In your design, assume a two-button mouse. Use mouse button 1 (usually the left button) for selection, activation of components, dragging, and the display of drop-down menus. Use mouse button 2 (usually the right button) to display contextual menus. Do not use the middle mouse button ; it is not available on most target platforms.

 Be aware that Macintosh systems usually have a one-button mouse, other personal computers and network computers usually have a two-button mouse, and UNIX systems usually have a three-button mouse.

 Restrict interaction to the use of mouse button 1 and mouse button 2. Macintosh users can simulate mouse button 2 by holding down the Control key while using mouse button 1.

The following figure shows the relative placement of mouse buttons 1 and 2 on Macintosh, PC, and UNIX mouse devices.

 

Figure 45 Cross-Platform Mouse Buttons and Their Default Assignments

 
Pointer Feedback

The pointer can assume a variety of shapes. For instance, in a text-editing application, the pointer might assume an I-beam shape (called a "text pointer" in the JDK) to indicate where the insertion point will be if the user presses the mouse button. The insertion point is the location where typed text or a dragged or pasted selection will appear. When the pointer moves out of the editor pane, it returns to its initial appearance as a default pointer.

The Java look and feel defines a set of pointer types that map to the corresponding native platform pointers; therefore, the appearance of pointers can vary from platform to platform, as shown in the following table. When no corresponding pointer exists in the native platform toolkit, the pointer is supplied by the JFC.

Table  7 Pointer Types Available in JDK 1.1 and the Java 2 SDK
Pointer Macintosh Windows 95 CDE Usage in Java Look and Feel Applications
Default
Pointing, selecting, or moving
Crosshair
Interacting with graphic objects
Hand
Panning objects by direct manipulation
Move
Moving objects
Text
Selecting or inserting text
Wait
Indicating that an operation is in progress and the user cannot do other tasks
S Resize
Adjusting the lower (southern) border of an object
N Resize
Adjusting the upper (northern) border of an object
E Resize
Adjusting the right (eastern) border of an object
W Resize
Adjusting the left (western) border of an object
NW Resize
Adjusting the upper-left (northwest) corner of an object
NE Resize
Adjusting the upper-right (northeast) corner of an object
SE Resize
Adjusting the lower-right (southeast) corner of an object
SW Resize
Adjusting the lower-left (southwest) corner of an object
 

 

 In addition to the shapes in Table 7, a pointer graphic can be defined as an image and created using Toolkit.createCustomCursor if you are using the Java 2 platform.

 
Mouse-over Feedback

Mouse-over feedback is a visual effect that occurs when users move the pointer over an area of an application window.

In the Java look and feel, mouse-over feedback can be used to show borders on toolbar buttons when the pointer moves over them. A slightly different effect is used to display tool tips. For details, see Toolbars and Tool Tips.

 
Clicking and Selecting Objects

In the Java look and feel, the selection of objects with the mouse is similar to the standard practice for other graphical user interfaces. Users select an object by clicking it. Clicking an unselected object also deselects any previous selection.

JFC-provided text selection follows these general rules:

 

  • A single click deselects any existing selection and sets the insertion point.
  • A double click on a word deselects any existing selection and selects the word.
  • A triple click in a line of text deselects any existing selection and selects the line.
  • Dragging (that is, moving the mouse while holding down mouse button 1) through a range of text deselects any existing selection and selects the range.

JFC-provided selection in lists and tables follows these general rules:

 

  • A click on an object deselects any existing selection and selects the object.
  • A Shift-click on an object extends the selection from the most recently selected object to the current object.
  • A Control-click on an object toggles its selection without affecting the selection of any other objects.

 
Displaying Contextual Menus

It can be difficult for users to find and access desired features given all the commands in the menus and submenus of a complex application. Contextual menus (sometimes called "pop-up menus") enable you to make such functions available throughout the graphical interface and to associate menu items with relevant objects.

Users can access contextual menus in two ways:

 

  • To pull down the menu, users can press and hold mouse button 2 over a relevant object. Then they can drag to the desired menu item and release the mouse button to choose the item.
  • To post the menu, users can click mouse button 2 over a relevant object. Then they can click the desired menu item to choose it.

     

Figure 46 Contextual Menu for a Text Selection

 

 Since users often have difficulty knowing whether contextual menus are available and what is in them, ensure that the items in your contextual menu also appear in the menu bar or toolbar of the primary windows in your application.

 Be sure that the commands in your contextual menu apply only to a selected object or group of objects. For instance, a contextual menu might include cut, copy, and paste commands limited to a selected text range, as shown in the preceding figure.

 Remember that users on the Microsoft Windows and UNIX platforms display a contextual menu by clicking or pressing mouse button 2. Macintosh users hold down the Control key while clicking.

 

Drag-and-Drop Operations

Drag-and-drop operations include moving, copying, or linking selected objects by dragging them from one location and dropping them over another. These operations provide a convenient and intuitive way to perform many tasks using direct manipulation. Common examples of drag and drop in the user interface are moving files by dragging file icons between folders or dragging selected text from one document to another. The Java 2 platform supports drag and drop between two Java applications or between a Java application and a native application. For example, on a Microsoft Windows system, users can drag a text selection from a Java application and drop it into a Microsoft Word document.

 
Typical Drag and Drop

Drag and drop in Java applications is similar to standard behavior on other platforms. Users press mouse button 1 while the pointer is over a source object and then drag the object by moving the pointer while holding down the mouse button. To drop the object, users release the button when the pointer is over a suitable destination. A successful drop triggers an action that depends on the nature of the source and destination. If the drag source is part of a range selection, the entire selection (for example, several file icons or a range of text) is dragged.

 
Pointer and Destination Feedback

During any drag-and-drop operation, your Java look and feel application needs to give visual feedback using the pointer and the destination.

 Provide the user with feedback that a drag operation is in progress by changing the shape of the pointer when the drag is initiated.

 Provide destination feedback so users know where the dragged object can be dropped. Use one or both of the following methods to provide destination feedback:

  • Change the pointer shape to reflect whether the object is over a possible drop target.
  • Highlight drop targets when the pointer is over them to indicate that they can accept the target.

 Java objects are specified by their MIME (Multipurpose Internet Mail Extensions) types, and the Java TM runtime environment automatically translates back and forth between MIME types and system-native types as needed. As an object is dragged over potential targets, each potential target can query the drag source to obtain a list of available data types and then compare that with the list of data types that it can accept. For example, when dragging a range of text, the source might be able to deliver the text in a number of different encodings or as plain text, styled text, or HTML text. If there is a match in data types, potential targets should be highlighted as the pointer passes over them to indicate that they can accept the dragged object.

 

Keyboard Operations

The Java look and feel assumes a PC-style keyboard. The standard ASCII keys are used, along with the following modifier keys: Shift, Control, and Alt (Option on the Macintosh); the function keys F1 through F12; the four arrow keys; Delete, Backspace, Home, End, Page Up, and Page Down. Enter and Return are equivalent. (Return does not appear on PC keyboards.)

A modifier key is a key that does not produce an alphanumeric character but can be used in combination with other keys to alter an action. Typical modifier keys in Java look and feel applications are Shift, Control, and Alt.

This section describes and provides recommendations for the use of keyboard operations , which include keyboard shortcuts, mnemonics, and other forms of navigation, selection, and activation that utilize the keyboard instead of the mouse. A mnemonic is an underlined letter that typically appears in a menu title, menu item, or the text of a button or other component. The underlined letter reminds users how to activate the equivalent command by pressing the Alt key and the character key that corresponds to the underlined letter. For instance, you could use a mnemonic to give keyboard focus to a text area or to activate a command button. A keyboard shortcut is a sequence of keys (such as Control-A) that activates a menu command.

 
Keyboard Focus

The keyboard focus (sometimes called "input focus") designates the active window or component where the user's next keystrokes will take effect. Focus typically moves when users click a component with a pointing device, but users can also control focus from the keyboard. Either way, users designate the window, or component within a window, that receives input. (There are exceptions: for instance, a left-alignment button on a toolbar should not take focus away from the text area where the actual work is taking place.)

 When a window is first opened, assign initial keyboard focus to the component that would normally be used first. Often, this is the component appearing in the upper-left portion of the window. If keyboard focus is not assigned to a component in the active window, the keyboard navigation and control mechanisms cannot be used. The assignment of initial keyboard focus is especially important for people who use only a keyboard to navigate through your application--for instance, those with visual or mobility impairments.

In the Java look and feel, many components (including command buttons, checkboxes, radio buttons, toggle buttons, lists, combo boxes, tabbed panes, editable cells, and tree views) indicate keyboard focus by displaying a rectangular border (blue, in the default color theme).

 

Figure 47 Keyboard Focus Indicated by Rectangular Border

Editable text components, such as text fields, indicate keyboard focus by displaying a blinking bar at the insertion point.

 

Figure 48 Keyboard Focus Indicated by Blinking Bar at Insertion Point

Menus indicate focus with a colored background for menu titles or menu items (blue, in the default color theme).

 

Figure 49 Keyboard Focus Indicated by Colored Background

Split panes and sliders indicate focus by darkening the drag-textured areas (blue, in the default color theme).

 

Figure 50 Keyboard Focus Indicated by Drag Texture

 
Keyboard Navigation and Activation

Keyboard navigation and activation enable users to move keyboard focus from one user interface component to another via the keyboard.

In general, pressing the Tab key moves focus through the major components; Shift-Tab moves through the components in the reverse direction. Control-Tab and Control-Shift-Tab work in a similar fashion and are particularly useful when keyboard focus is in an element that accepts tabs, such as a text area or a table. Arrow keys are often used to move within groups of components--for example, Tab puts focus in a set of radio buttons and then the arrow keys move focus among the radio buttons. However, the Tab key is used to move among checkboxes.

Once an element has focus, pressing the spacebar typically activates it or selects it. In a list, pressing Shift-spacebar extends the selection; pressing Control-spacebar makes another selection without affecting the current selections.

Some components do not need explicit keyboard focus to be operated. For example, the default button in a dialog box can be operated by pressing the Enter or Return key without the default button having keyboard focus. Similarly, scrollbars can be operated from the keyboard if focus is anywhere within the scroll pane.

Keyboard navigation can be useful not only for accessibility purposes, but also for power users, users who prefer the keyboard over the mouse, or users who choose alternative input methods like voice input or onscreen keyboards.

 Ensure that all application functions are accessible from the keyboard by unplugging the mouse and testing the application's keyboard operations.

 Some of the keyboard operations in the tables in Appendix A are temporarily incomplete or unimplemented. However, the key sequences listed in this appendix should be reserved for future versions of the JFC and the Java 2 platform.

 The setNextFocusableComponent method from JComponent can be used to set the order for tabbing by chaining components together--specifying for each component what the next component in the sequence is.

The common operations for keyboard navigation and activation in the Java look and feel are summarized in the following table. Within the table, the term "group" refers to a group of toolbar buttons, menu titles, text, or table cells.

Table  8 Common Navigation and Activation Keys 
Action Keyboard Operation
Navigates in, navigates out Tab 1
Navigates out of a component that accepts tabs Control-Tab 1
Moves focus left one character or component within a group Left arrow
Moves focus right one character or component within a group Right arrow
Moves focus up one line or component within a group Up arrow
Moves focus down one line or component within a group Down arrow
Moves up one view Page Up
Moves down one view Page Down
Moves to the beginning of data; in a table, moves to the beginning of a line Home
Moves to the end of data; in a table, moves to the last cell in a row End
Activates the default command button Enter or Return
Dismisses a menu or dialog box without changes Escape
Activates or selects the component (with keyboard focus) Spacebar
1 With Shift key, reverses direction

 

 

 
Keyboard Shortcuts

Keyboard shortcuts are keystroke combinations (consisting of a modifier key and a character key, like Control-Z) that activate a menu item from the keyboard even if the menu for that command is not currently displayed. Unlike mnemonics, keyboard shortcuts do not post menus; rather, they perform the indicated actions directly.

 

Figure 51 Edit Menu With Keyboard Shortcuts and Mnemonics

To use a keyboard shortcut in Java look and feel applications, users hold down the Control key (and optionally, an additional modifier key, such as Shift) and press the character key that is shown after the menu item. Typing the keyboard shortcut has the same effect as choosing the menu item. For instance, to undo an action, users can either choose the Undo item from the Edit menu or hold down the Control key and press Z.

 Do not use the Meta key (the Command key on the Macintosh platform) for a keyboard shortcut, except as an alternate for Control. It is not available on many target platforms.

 Specify keyboard shortcuts for frequently used menu items to provide an alternative to mouse operation. The Java look and feel displays keyboard shortcuts using standard abbreviations for key names, separated by hyphens.

 Be aware of and use the common shortcuts across platforms that are summarized in the following table.

Table  9 Common Keyboard Shortcuts  
Sequence Equivalent
Ctrl-N New (File menu)
Ctrl-O Open (File menu)
Ctrl-S Save (File menu)
Ctrl-P Print (File menu)
Ctrl-W Close (File menu)
Ctrl-Z Undo (Edit menu)
Ctrl-Y Redo (Edit menu)
Ctrl-X Cut (Edit menu)
Ctrl-C Copy (Edit menu)
Ctrl-V Paste (Edit menu)
Ctrl-F Find (Edit menu)
Ctrl-G Find Again (Edit menu)
Ctrl-A Select All (Edit menu)
 

 Since keyboard shortcuts are not always equivalent on different platforms, ensure that any new keyboard shortcuts you have created are compatible with existing shortcuts on all your target platforms.

 
Mnemonics

Mnemonics provide yet another keyboard alternative to the mouse. A mnemonic is an underlined letter in a menu title, menu item, or other interface component. It reminds the user how to activate the equivalent command by simultaneously pressing the Alt key and the character key that corresponds to the underlined letter.

 

Figure 52 File Menu With Mnemonics and Keyboard Shortcuts

When keyboard focus is not in a text element, the Alt modifier is not always required. Menus are an example. For instance, to choose the Exit command from the File menu, the user can hold down the Alt key and press F to post the File menu, and then press X.

Once users have displayed a menu with a keyboard sequence, the subsequent key they press will activate a command only from that menu. Hence, users can press Alt-F to display the File menu and then type A to activate the Save As command, or press Alt-E to display the Edit menu, and then type A to activate the Select All command.

You can also provide mnemonics for components within the dialog boxes in your applications. However, it is important to note that this situation requires that you use a modifier key. For instance, within a dialog box, you might want to provide a mnemonic for the Help button. Once keyboard focus has moved within the dialog box, users press Alt, and then H to activate the Help button.

 Do not associate mnemonics with the default button or the Cancel button in a dialog box. Use Enter or Return for the default button and Escape for the Cancel button instead.

 Choose mnemonics that avoid conflicts. For instance, you cannot use the letter P as the mnemonic for both the Print and Page Setup commands.

 When you assign mnemonics, follow these guidelines in the specified order.

1. Use common mnemonics as they appear in Table 10 below.
2. If the mnemonic does not appear in the table of common mnemonics ( Table 10), choose the first letter of the menu item. (For instance, choose J for Justify.)
3. If the first letter of the menu item conflicts with those of other items, choose a prominent consonant. (For instance, the letter S may have already been designated as the mnemonic for the Style command. Therefore, choose the letter Z as the mnemonic for the Size command.)
4. If the first letter of the menu item and the prominent consonant conflict with those of other menu items, choose a prominent vowel.

Table  10 Common Mnemonics 
Menu Titles Menu Items
File New, Open, Close, Save, Save As, Page Set up, Print, P references, E xit
Edit Undo, Redo, Cu t, Copy, Paste, Find, Fin d Again, Select All
Help Contents, Tutorial, Index, Search, About Application
 

 

 The setMnemonic method can be used to specify mnemonics on buttons, checkboxes, radio buttons, toggle buttons, and menu titles. The setDisplayedMnemonic method can be used for labels, and the setAccelerator method for menu items.


 

Java homepage  :  Design Guidelines Previous  |  Next  |  Contents  |  Index  |  Search

Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.

Left Curve
Java SDKs and Tools
Right Curve
Left Curve
Java Resources
Right Curve
JavaOne Banner
Java 8 banner (182)