Skip to main content

A extended right menu assist for text component.

1 reply [Last post]
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:

2)non blank text document:

3)with some text selected:

4)support quick search:(impl copied from org.jdesktop.swingx.JXEditorPane)

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:

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() {
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 can download from this url:
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.
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.