Java Reference
In-Depth Information
frame.setSize(250, 250);
frame.setVisible(true);
}
};
EventQueue.invokeLater(runner);
}
}
The example in Listing 15-4 uses the
TextUtilities
support class shown in Listing 15-5.
There's no direct way to find out if a specific action for a specific key exists in the
actions
property array. Instead, you must manually search for it. The
public static Action
findAction(Action actions[], String key)
method does the searching for you.
Listing 15-5.
TextUtilities Support Class
import javax.swing.*;
import javax.swing.text.*;
import java.util.Hashtable;
public final class TextUtilities {
private TextUtilities() {
}
public static Action findAction(Action actions[], String key) {
Hashtable<Object, Action> commands = new Hashtable<Object, Action>();
for (int i = 0; i < actions.length; i++) {
Action action = actions[i];
commands.put(action.getValue(Action.NAME), action);
}
return commands.get(key);
}
}
■
Note
For security reasons, the
cut()
and
copy()
methods of the
JPasswordField
class do not place
the current contents onto the system clipboard (the system will beep instead). You can still
paste()
some-
thing from the clipboard into a
JPasswordField
, though.
Document Interface
The
Document
interface defines the data model for the different text components. Implementa-
tions of the interface are meant to store both the actual content as well as any information to
mark up the content (with bold, italics, or color). While all the content will be text, the way in
which the text component displays the content could result in nontextual output, such as an
HTML renderer.