JDK-4818418 : Windows L&F missing text field context menu
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2003-02-13
  • Updated: 2003-02-13
  • Resolved: 2003-02-13
Related Reports
Relates :  
Description
Name: rmT116609			Date: 02/13/2003


FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)

FULL OPERATING SYSTEM VERSION :
Windows NT Version 4.0

ADDITIONAL OPERATING SYSTEMS :
Window 2000, Windows 98 SE2

A DESCRIPTION OF THE PROBLEM :

Windows platforms provide a context menu popup in text fields with the following menu items: Undo, Redo, Cut, Copy, Paste, Delete, and Select All.  The menu is activated using the usual shortcuts, Shift-F10 or right mouse click.

This menu is missing altogether from the Swing Windows L&F.  It should probably be in at least JTextField and JComboBox. 

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. java -jar SwingSet2.jar
2. go to any text field (such as one in the file chooser demo or the dialogs in the option pane demo)
3. right click mouse in text field.  No menu will come up.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected results are visible by using WindowsKey-F to bring up the Windows "Find" application.  Right click in any textfield there and the popup menu will be shown.

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER WORKAROUND :
Implement popup menu for all JTextFields, etc...
(Review ID: 181264) 
======================================================================

Comments
WORK AROUND Subclass JTextField and implement your own context menu. import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.undo.*; public class MyTextField extends JTextField { private JPopupMenu contextMenu; private UndoManager undoManager; public MyTextField() { undoManager = new UndoManager(); contextMenu = new JPopupMenu(); UndoAction undoAction = new UndoAction(); contextMenu.add(new JMenuItem(undoAction)); getDocument().addUndoableEditListener(undoAction); contextMenu.addSeparator(); addToContextMenu("Cut", DefaultEditorKit.cutAction); addToContextMenu("Copy", DefaultEditorKit.copyAction); addToContextMenu("Paste", DefaultEditorKit.pasteAction); addToContextMenu("Delete", DefaultEditorKit.deleteNextCharAction); contextMenu.addSeparator(); addToContextMenu("Select All", DefaultEditorKit.selectAllAction); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { contextMenu.show(MyTextField.this, e.getX(), e.getY()); } } }); } private void addToContextMenu(String label, String actionName) { Action action = getActionMap().get(actionName); if (action != null) { JMenuItem mi = new JMenuItem(action); mi.setText(label); contextMenu.add(mi); } } class UndoAction extends AbstractAction implements UndoableEditListener { public UndoAction() { super("Undo"); setEnabled(false); } public void undoableEditHappened(UndoableEditEvent e) { undoManager.addEdit(e.getEdit()); setEnabled(undoManager.canUndo()); } public void actionPerformed(ActionEvent e) { try { undoManager.undo(); } catch (CannotUndoException ex) { } setEnabled(undoManager.canUndo()); } } public static void main(String[] args) { JFrame frame = new JFrame(); JTextField tf = new MyTextField(); frame.getContentPane().add(tf); frame.pack(); frame.setLocation(200, 200); frame.setVisible(true); } } ###@###.### 2003-05-16
16-05-2003

EVALUATION This is application specific. ###@###.### 2003-02-13
13-02-2003