views:

117

answers:

2

I am building a small GUI application where I use drag and drop internally on custom components. Now I want to have context menus on the components which have drag and drop enabled.

Now my question is, how do I properly distinguish between these two events. For context menus there is an API function, but for DnD I did not find one. I used mouse down to trigger DnD, but with that for example on Windows context menus stop working because they are triggered on mouse up.

A: 

For DnD use a combination of mouse down and mouse move.

For context menu use the mouse clicked event (so the menu comes up when the mouse button is released not when it's pressed).

Tom
A: 

The Swing tutorial has sections on "How to Use Menus" and "Drag and Drop".

The section on menus show how to display a popup by checking the "isPopupTrigger" of the MouseEvent. Although since JDK5 this process is easier as the setComponentPopupMenu()method has been added.

The secton on DnD shows how to use the built in DnD support.

camickr