tags:

views:

592

answers:

1

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?

A: 

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.

camickr
Would you mind posting at least some of the content of your blog post here? That way it's here on the site permanently.
John K
I keep the explanation and examples in one place so it only ever needs to be maintained in one place. That way when I answer questions I only need to provide a simple answer and I can spend more time answering other question. If there is something specific that you used that you think is important, you can paste it here yourself I'm not worried about people copying or using the code.
camickr