X-Received: by 10.224.86.200 with SMTP id t8mr9785363qal.0.1370961875646; Tue, 11 Jun 2013 07:44:35 -0700 (PDT) X-Received: by 10.50.117.106 with SMTP id kd10mr304851igb.14.1370961875611; Tue, 11 Jun 2013 07:44:35 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!ch1no4054546qab.0!news-out.google.com!y6ni1724qax.0!nntp.google.com!ch1no4054544qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.gui Date: Tue, 11 Jun 2013 07:44:35 -0700 (PDT) In-Reply-To: <534db8a1-6fb0-47a4-a532-30e4bbbf0495@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=130.76.32.78; posting-account=_7xgmwoAAADi7iXKBO-oX5zbCfSzsCV0 NNTP-Posting-Host: 130.76.32.78 References: <83dd7dc7-c9d4-41b2-ada2-be50758aecf3@googlegroups.com> <534db8a1-6fb0-47a4-a532-30e4bbbf0495@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <10095392-e92c-4285-b5f8-dbde7c18cb1a@googlegroups.com> Subject: Re: TransferHandler exportAsDone called before exportAsDrag returns From: FredK Injection-Date: Tue, 11 Jun 2013 14:44:35 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.java.gui:5360 On Monday, June 10, 2013 3:14:11 PM UTC-7, Lew wrote: > FredK wrote: > I have a subclass of JPanel for which I am trying to imple= ment > drag-and-drop. I add a mouse listener to the component, and in > its= mousePressed() method I call > JComponent c =3D (JComponent)event.getSourc= e(); > TransferHandler th =3D c.getTransferHandler(); > th.exportAsDrag( co= mp, event, TransferHandler.COPY ); > > The problem is that the handler's ex= portAsDone() method is > called immediately - before exportAsDrag() returns= , and > before the mouse is moved or released. Can you provide an SSCCE? ht= tp://sscce.org/ The problem appears to be in the part of the code you haven= 't shown us. Are you managing events on the EDT properly? -- Lew I hadn't realized that JPanel (or I guess JComponent) had built-in DnD for = bean properties - didn't see any mention of it in the Javadoc tutorials. I now have it working - I had been using "text" as the argument for Transfe= rHandler, but my component did not have a "text" property. For example, this does work (and works for "text" when I add a "text" prope= rty to my panel): package boeing.geoduck.viewer.swingitems; import java.awt.BorderLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; import javax.swing.TransferHandler; public class DragTest { public static void main( String args[] ) { SwingUtilities.invokeLater( new Runnable() { public void run() { JFrame frame =3D new JFrame(); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setSize( 300, 150 ); JPanel w =3D new JPanel(); frame.add( w, BorderLayout.CENTER ); w.setTransferHandler( new TransferHandler( "background" ) ); w.addMouseListener( new MouseAdapter() { @Override public void mousePressed( MouseEvent me ) { JComponent comp =3D (JComponent) me.getSource(); TransferHandler handler =3D comp.getTransferHandler(); int actions =3D handler.getSourceActions( comp ); System.out.println( actions ); handler.exportAsDrag( comp, me, TransferHandler.COPY ); } } ); frame.setVisible( true ); } } ); } } --=20 Fred K