JMEDesktop and events

After having some problems with drag and drop we experience a problem with focus change by a focus traversal key (Tab) which is just ignored in JMEDesktop.

Forcing a stack trace in a swing applet shows that the events come from EventDispatchThread and this looks like to take several special cases into account when dispatching events. As far as I can see JMEDesktop tries to do the same job and for basic events this works fine.

Problems occur in events that are not handled directly by the current component like focus traversal and drag and drop.

EventDispatchThread works with an EventQueue and maybe it would work to create such an EventQueue and start EventDispatchThread from JMEDesktop?

This is just a theory after looking around, I'm not a swing expert.

I have the following problem with focus…

Imagine you have an JME app with a textfield in window mode and custom mouse cursor.

If you do some input on the textfield, it's ok. But if you then use alt + tab keys to switch application and then switch back to JME app the textfield doesn't get input anymore.

It looks like my theory is wrong. I changed JMEDesktop.dispatchEvent to:


where eventQueue is

        eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();

but it drops most of the events now. EventDispatchThread is packet private so we cannot just use that either.

... stuck again.

Next try: Create a custom DragGestureRecognizer and I'm almost there, but now:

02.05.2006 23:27:03 de.worldofmystery.client.gui.DndPanel dragGestureRecognized
INFO: called dragGestureRecognized
02.05.2006 23:27:03 de.worldofmystery.client.gui.DndPanel dragGestureRecognized
INFO: invalid dnd action
java.awt.dnd.InvalidDnDOperationException: Cannot grab pointer: already grabbed
        at sun.awt.X11.XDragSourceContextPeer.throwGrabFailureException(
        at sun.awt.X11.XDragSourceContextPeer.startDrag(
        at sun.awt.dnd.SunDragSourceContextPeer.startDrag(
        at java.awt.dnd.DragSource.startDrag(
        at java.awt.dnd.DragSource.startDrag(
        at de.worldofmystery.client.gui.DndPanel.dragGestureRecognized(
        at de.worldofmystery.client.gui.JMEMouseDragGestureRecognizer$
        at java.awt.event.InvocationEvent.dispatch(
        at java.awt.EventQueue.dispatchEvent(
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(
        at java.awt.EventDispatchThread.pumpEvents(
        at java.awt.EventDispatchThread.pumpEvents(

I don't know what that should tell me : "Cannot grab pointer: already grabbed". Is there anything I can do to release that grab (whatever that is) ?

Galun said:

I don't know what that should tell me : "Cannot grab pointer: already grabbed". Is there anything I can do to release that grab (whatever that is) ?

Might be lwjgl that grabs it if you havn't done MouseInput.get().setCursorVisible( true ) - but one would not want this in a game :|

I tried with both true and false but the error persists. It's really a pity. I think I'm really near to a working drag and drop on JMEDesktop.

Is there a way to force lwjgl to give up the grab - at least for the time of the drag?

No idea :expressionless:

Ah, I see there is a Mouse.setGrabbed(false) if you do a setCursorVisible(true) which is what I did in the test program anyway.

Is the source of this available to check what it does?


Found this, looks like the source

Thanks for the link.

It looks like the mouse grab is blocked deep inside Xlib. Even if we would find a way to release there it might not be portable and I think it might have side effects.

This is really annoying. I just came across another thing where I wished I had working drag and drop. In WoM client I added a shortcut panel and drag and drop to set the shortcuts would be the most comfortable.

can you do a happy medium ( Uri Gellar is a happy medium, least i think he is happy ).

render a quad with the component graphics, attach it to a cursor node, on mouse release detect if cursor is over a self specified drop target coordination.

right: just don't use actual dnd but do it yourself - you would have to do so with another gui package, too.

I see I think we will never get Swing drag and drop working.

I try to get something general in JMEDesktop and let you know.

Would have thought its quite a simple operation ( said he who has spent 3 hours trying to sort out custom Node culling ).

The swing components all have an easy way to get the graphics, pop that into a buffered image etc… then an convert to an image using ImageIcon etc and pop it into TextureManager.loadTexture. ( Many ways of doing of course  - Irrisor did something to render the desktop in the first place, so you could probably use that )

It works! I have to clean up a bit but it seems to do what I expected.

Can you put together a test for inclusion in jmetest that demonstrates this?  Would probably prevent headaches for other people down the road.

true - what did you finally do to achieve it, Galun?

It's more or less a stripped down version of what Swing does but without using the drag source context.

I have to do some more tests, but if you want to have a look this is what I have:

It works for the first drag and drop action but there are some problems:

If a JInternalFrame has focus I miss mouse pressed events. Due to the missing events drag and drop cannot work reliably.

Here are the classes for drag and drop as well as some for testing:

I think I found the problem. The mouse events currently are dispatched to the component under the pointer, but they should be dispatched to the component that handles the event which might not be the same.

Consider this example:


| +---JPanel