Duplicate :
|
THIS BUG REPORT IS FILED SOLELY TO SUPPORT AN ESCALATION. In the example below, attempting to drag and drop a label onto a text field causes the application to hang in 1.2.2-004. The same code works fine with 1.3, build R., and with the 1.2.2 Solaris reference JDK. A similar problem was reported in bug #4269666 and fixed for Kestrel. import java.util.*; import java.io.*; import java.net.*; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.awt.datatransfer.*; import java.awt.dnd.*; import javax.swing.*; import javax.swing.event.*; public class TestBed { protected JFrame m_frame; public static void main(String args[]) { new TestBed().run(); } public TestBed() { m_frame = new JFrame("TestBed"); m_frame.addWindowListener(new AppWindowListener()); m_frame.setLocation(100, 100); m_frame.setSize(200, 200); m_frame.getContentPane().add(new DragLabel("Hey! Drag me!"), BorderLayout.NORTH); m_frame.getContentPane().add(new DropText(), BorderLayout.SOUTH); } public void run() { m_frame.show(); } public class DragLabel extends JLabel implements DragGestureListener, DragSourceListener { protected DragSource m_dragSource; protected DragGestureRecognizer m_dragGestureRecognizer; public DragLabel(String text) { super(text); m_dragSource = DragSource.getDefaultDragSource(); m_dragGestureRecognizer = m_dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this); } public void dragGestureRecognized(DragGestureEvent evt) { evt.startDrag(null, new StringSelection(getText()), this); } public void dragDropEnd(DragSourceDropEvent evt) { } public void dragEnter(DragSourceDragEvent evt) { } public void dragExit(DragSourceEvent evt) { } public void dragOver(DragSourceDragEvent evt) { } public void dropActionChanged(DragSourceDragEvent evt) { } } public class DropText extends JTextField implements DropTargetListener { protected DropTarget m_dropTarget; public DropText() { super(); m_dropTarget = new DropTarget(this, this); } public void dragEnter(DropTargetDragEvent evt) { evt.acceptDrag(evt.getDropAction()); } public void dragExit(DropTargetEvent evt) { } public void dragOver(DropTargetDragEvent evt) { evt.acceptDrag(evt.getDropAction()); } public void drop(DropTargetDropEvent evt) { Transferable transferable; String text; evt.acceptDrop(evt.getDropAction()); transferable = evt.getTransferable(); try { text = (String)transferable.getTransferData(DataFlavor.stringFlavor); setText(text); evt.dropComplete(true); // This example was taken from bug #4261459. // // In this case the next line causes a hang in the following java versions // //java version "1.2.2" //Classic VM (build JDK-1.2.2-003, native threads, symcjit) // //java version "1.3beta" //Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O) //Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode) // JOptionPane.showMessageDialog(m_frame, "Drop: " + getText(), "Drop!", JOptionPane.INFORMATION_MESSAGE); } catch (UnsupportedFlavorException e) { evt.dropComplete(false); } catch (IOException e) { evt.dropComplete(false); } } public void dropActionChanged(DropTargetDragEvent evt) { evt.acceptDrag(evt.getDropAction()); } } public class AppWindowListener extends WindowAdapter { public void windowClosing(WindowEvent evt) { m_frame.dispose(); System.exit(0); } } }