item.addActionListener(new DefaultEditorKit.PasteAction());
menu.add(item);
item = new MenuItem("Select All", new MenuShortcut(KeyEvent.VK_A));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
KeyboardFocusManager kfm =
KeyboardFocusManager.getCurrentKeyboardFocusManager();
Component comp = kfm.getFocusOwner();
if (comp instanceof TextComponent) {
((TextComponent) comp).selectAll();
} else if (comp instanceof JTextComponent) {
((JTextComponent) comp).selectAll();
}