Skip to main content

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

2 replies [Last post]
augusto
Offline
Joined: 2003-06-11
Points: 0

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.
zander
Offline
Joined: 2003-06-13
Points: 0

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: http://uic.sourceforge.net/api/uic/themes/UICTheme.html
for 2 see the implementation of method addCustomEntriesToTable() in class:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/uic/uicompiler/uic/themes...

Hope this helps!

(YEAH 100 posts :))

augusto
Offline
Joined: 2003-06-11
Points: 0

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.