This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
A user on the dev@openide list asked why the Cut, Copy and Paste items on the edit menu are not enabled when a standard Swing component has focus since these components offer default actions for cutting, copying and pasting text. It seems that these can only be enabled by changing each TopComponent in the application to swap out the action map to use the Swing actions when the TopComponent receives focus and then swapping it back again when the TopComponent loses focus using code like: @Override protected void componentActivated() { ActionMap actionMap = getActionMap(); actionMap.put(DefaultEditorKit.copyAction, new DefaultEditorKit.CopyAction()); actionMap.put(DefaultEditorKit.cutAction, new DefaultEditorKit.CutAction()); actionMap.put(DefaultEditorKit.pasteAction, new DefaultEditorKit.PasteAction()); super.componentActivated(); } @Override protected void componentDeactivated() { ActionMap actionMap = getActionMap(); actionMap.put(DefaultEditorKit.copyAction, SystemAction.get(CopyAction.class)); actionMap.put(DefaultEditorKit.cutAction, SystemAction.get(CutAction.class)); actionMap.put(DefaultEditorKit.pasteAction, SystemAction.get(PasteAction.class)); super.componentDeactivated(); } This is tedious and duplicative. Perhaps there is an easier way, in which case it should be documented. If not, would it be possible to make the NetBeans Cut, Copy and Paste actions could delegate to the Swing Cut, Copy and Paste actions so that cutting, copying and pasting text as well as nodes will work. For context, see this thread: http://openide.netbeans.org/servlets/ReadMsg?list=dev&msgNo=38176
I've created TextTopComponent with one JTextArea and as far as I can tell, the Copy and Cut actions from Toolbar are working correctly. But: The copy and cut actions from Edit menu do not work. The paste action does not even get enabled.
The reason why toolbar works and menu does not is that the code in: DelegateActionMap.java: owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); returns JTextArea in the first place and JRootPane in the second, Standa, please help me!
Per Standa's suggestion: Using getPermanentFocusOwner() in core-main#a362f628409b
Created attachment 102859 [details] My testing application
Created attachment 102860 [details] Changes that make it work (without tests)
Integrated into 'main-golden', will be available in build *201011100000* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main/rev/a362f628409b User: Jaroslav Tulach <jtulach@netbeans.org> Log: #161211: Using getPermanentFocusOwner()
core-main#c0de415adb58
Integrated into 'main-golden', will be available in build *201011110000* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main/rev/a9af868ff294 User: Jaroslav Tulach <jtulach@netbeans.org> Log: #161211: TopComponent's ActionMap needs to return keys of currently focused component from allKeys()
I verified that cut/copy/paste work correctly on a textfield inside a TopComponent using all combinations of those actions from the main menu, toolbar buttons and context menu. This was done using the most recent nightly build (details below). Thanks! Product Version: NetBeans IDE Dev (Build 201011110000) Java: 1.6.0_21; Java HotSpot(TM) Client VM 17.0-b16 System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)