2 Replies Latest reply on Apr 8, 2010 8:07 AM by InteractiveMesh

    Drag&Drop + JComponent = NullPointerException

    843851
      Hi,

      i've implemented the Drag&Drop like this:
      [http://javafx.com/samples/DragAndDrop/index.html]

      i've added to the DragDrop code, that if i drag my object, it get's removed from the local Group and added it to the TopLevel Group of the scene to avoid the clipping
      of my layout.
      That works, without the JComponent.

      ok, i've added a JLayeredPane behind my draggable. But now, if i want to drag my object, i get nullPointerExceptions (but the drag&drop still works):
      Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
              at com.sun.embeddedswing.EmbeddedEventQueue.moveToVisibleAndOnScreen(EmbeddedEventQueue.java:155)
              at com.sun.embeddedswing.EmbeddedEventQueue.beforeDispatch(EmbeddedEventQueue.java:376)
              at com.sun.embeddedswing.EmbeddedEventQueue.access$400(EmbeddedEventQueue.java:74)
              at com.sun.embeddedswing.EmbeddedEventQueue$EventQueueDelegateFactory$2.call(EmbeddedEventQueue.java:728)
              at com.sun.java.swing.SwingUtilities3$EventQueueDelegateFromMap.beforeDispatch(SwingUtilities3.java:198)
      i think it has something to do with inserting in the TopLevel Group and MouseEvents.

      Any suggestions?

      Thanks!
        • 1. Re: Drag&Drop + JComponent = NullPointerException
          843851
          I am developing a GUI software in JavaFx and this also happened to me.
          I have found a way to resolve this problem. The NullPointerException was
          thrown when the onMouseDragged method in javafx Node receiving the first
          mouse-drag event added the gesture Node to the scene (the gesture
          node moves with the cursor while dragging), and later the mouse was
          draged over a JComponent wraped by a SwingComponent. To overcome
          this problem I have used FX.deferAction method for adding the gesture Node
          to the scene after returning from the first mouse-drag event.

          Eldad Zamler
          • 2. Re: Drag&Drop + JComponent = NullPointerException
            InteractiveMesh
            Hi,

            there seems to be a bug in:

            com.sun.embeddedswing.EmbeddedEventQueue.moveToVisibleAndOnScreen(EmbeddedEventQueue.java:155)

            I reported the bug "*RT-4912 SwingComponent toFront/toBack*" already on 2009/06/07. Nothing has happened so far. Apparently, SwingComponent is treated as a second-class citizen.

            August