Skip to main content

A extended right menu assist for text component.

1 reply [Last post]
theface
Offline
Joined: 2005-09-18
Points: 0

In windows,you can use the right click for any text components(else disabled by applications),it will show a popup menu contains undo,copy,cut,paste,delete,select all,etc.this is a usable feature,a user friendly feature.

I am using java swing to develoment my app now,and this user friendly feature is not support ,so I extend some utils to support this feature based swingx.following example imgs will show you:
1)blank/empty text document:
http://www.motree.com/imageservices/trma-01.png

2)non blank text document:
http://www.motree.com/imageservices/trma-02.png

3)with some text selected:
http://www.motree.com/imageservices/trma-03.png

4)support quick search:(impl copied from org.jdesktop.swingx.JXEditorPane)
http://www.motree.com/imageservices/trma-04.png

Supported actions:
[Action] [Key]
Undo Ctrl+Z
Redo Ctrl+Y
Find Ctrl+F
Cut Ctrl+X
Copy Ctrl+C
Paste Ctrl+V
Delete Delete
Select All Ctrl+A

Supported languages:
en_US
zh_CN

Supported text components:
support any component type of javax.swing.text.JTextComponent.

This implements is based swing,not crack for swing.a example:

class JXTextPane extends JTextPane {
public JXTextPane() {
super();
SwingXUtils.bindAssistOnRightClick(this);//this is my extended utils.
}
}

In my local swingx build, JXTextArea,JXTextField,JXTextPane,JXEditorPane is supported now,sorry for swingx team,I changed your codes.but swingx is a very good project.

I agree some body dosen't like this feature.but will helped for some body.you can download from this url:
http://www.motree.com/imageservices/trmaExt-swingx.zip
maybe some code has no comment/javadoc.:)

Finally.Sorry for my broken english.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08
Points: 0

It is probably a better bet to create a listener for permanentFocusOwner and place it on the KeyboardFocusManager. Check whether the new JTextComponent contains a popup menu and if no, assign your special menu; remove on focus lost. Then you are only installing the code in one place, there is no need to modify sources and you can still use core components or someone else's components that extend JTextComponent without performing additional trickery.

Karl