Skip to main content

Cut / Copy / Paste menu on JTextFields, how to add it for all instances ...

2 replies [Last post]
Joined: 2003-06-11

Here's what I want, I'd like to have a cut/copy/paste menu for all JTextFields in our application. This is pretty easy, you can either create your own CopyPasteTextField object that implements this, or create a static method in a utility class to add the menu to a text field.

However, in our application, we have many people adding ui widgets all over the place, I'd like to find out if there's a way to just add this menu via the look and feel mechanism, so that the menu is added globally, with no manual interaction from a coding perspective.

Does anybody have any idea how to do this?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-13

Yeah, not really a problem.

What kind of theme do you use currently?

You have to create a class that extends MetalTextFieldUI and add the stuff in an overloaded installDefaults method.

1) you want to notify Swing about your own class; you have to set a theme, and 2) you have to specify your class as the textfield UI.

for 1 see:
for 2 see the implementation of method addCustomEntriesToTable() in class:

Hope this helps!

(YEAH 100 posts :))

Joined: 2003-06-11

At the very minimum, I'm hoping on adding this for the Windows look and feel, since our users are used to that right click menu.

Ideally, it could be done for all look and feels, but I think it's ok to only add it to the windows one, since the native widget is supposed to have that method.