Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global context menu for Cut/Copy/Paste with JTextField in Swing App?

What is the best way to implement a global default context menu for a Swing app that has the Windows-standard cut/copy/paste/etc. popup menu for things like JTextField? Tim Boudreau suggested installing a custom UI delegate in this javalobby thread but that was written with Java 5 in mind, so I'm wondering if there's a better way today.

Are there plans to add this behavior in a future version of Swing itself?

like image 867
John K Avatar asked Aug 30 '09 04:08

John K


1 Answers

Good timing. My blog entry for tomorrow was going to be about using Global Event Listeners. The simple answer is to use an AWTEventListener (instead of a custom EventQueue) to listen for MouseEvents and to then check the mouse event to see if it is a popup trigger.

I'll post the link to the entry tomorrow afternoon (EDT) when I get it published.

Then you can decide which approach is better.

You can now check out the Global Event Listeners entry for a really simple example of using an AWTEventListener.

like image 139
camickr Avatar answered Oct 26 '22 10:10

camickr