-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.1
-
x86
-
windows_nt
Name: vi73552 Date: 04/08/99
When code containing DnD, a MouseListener, and CustomCursors has all
three functions activated, the VM hangs, and only Ctrl-C works.
This problem was reported at JDK v1.2Beta4 and is still there at
JDK v1.2.1 (the beta, not the security update). We *really* need
this fixed, it is causing us a problem in our ArcIMS product that is
now at Beta 1 release stage. Below is a sample app that demos the
problem. Since I cannot email you, I am unable to supply the
custom cursor GIF, but I'm sure anything will do, it is 32x32 pixels
in size. I also have a simple Makefile to help demo, but all you
really have to do is compile then run the app, then follow the
instructions below.
*PLEASE NOTE* this is a Windows NT issue, no problem on SOlaris.
-------------------------------------
D:\Russell\projects\BetaJdk>java -version
java version "1.2.1"
Classic VM (build JDK-1.2.1-K, native threads, symcjit)
D:\Russell\projects\BetaJdk>java -fullversion
java full version "JDK-1.2.1-K"
D:\Russell\projects\BetaJdk>
-------------------------------------
Instructions
-------------------------------------
Compile, then run the app.
The app, when running, has
- a grey "DropArea" at the top,
- a pink "DragArea" at the bottom left,
- a textfield where you can enter text that will be dragged,
- a button that when clicked installs a mouse listener, and,
- another button that when clicked installs a custom cursor.
Test the DnD by dragging from the pink DragArea onto the DropArea,
and see the text appear in the DropArea - if not convinced, change
text in the TextField and repeat. This should work.
Next, click the Mouse button to install the MouseListener.
Test the MouseListener by clicking in the DropArea and see the
MouseEvent show in the DropArea. Repeat the DnD and confirm this
still works ok.
Finally, click the CustomCursor button to install the CustomCursor.
Move the mouse into the DropArea to see the CustomCusror. Click in
the DropArea to see the MouseEvent still working. Try to repeat
the DnD operation, it should fail. Actually, the failure sometimes
occurs in different places, say when you click again in the DropArea.
But when it fails, everything hangs, and you have to Ctrl-C it.
Reminder - this is for NT.
-------------------------------------
SourceCode of sample app that demos the problem
-------------------------------------
public class TestDnD extends javax.swing.JFrame {
TestDrop theDrop;
public TestDnD() {
setSize(550,200);
getContentPane().setLayout(new java.awt.BorderLayout(5,5));
theDrop = new TestDrop();
getContentPane().add(theDrop, java.awt.BorderLayout.CENTER);
javax.swing.JPanel p = new javax.swing.JPanel(false);
javax.swing.JTextField f = new javax.swing.JTextField("text to be dragged");
p.add(new TestDrag(f));
p.add(f);
javax.swing.JButton b1 = new javax.swing.JButton("ADD MOUSE");
p.add(b1);
javax.swing.JButton b2 = new javax.swing.JButton("ADD CUSTOM CURSOR");
p.add(b2);
getContentPane().add(p, java.awt.BorderLayout.SOUTH);
addWindowListener(
new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
super.windowClosing(e);
TestDnD.this.setVisible(false);
System.exit(0);
}
}
);
b1.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("action performed -> mouse listener installed.");
theDrop.addMouseListener(
new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent e) {
theDrop.setText(e.toString());
}
}
);
}
}
);
b2.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("action performed -> custom cursor installed.");
java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
theDrop.setCursor(tk.createCustomCursor(tk.getImage(getClass().getResource("/pan_cur.gif")), new java.awt.Point(6,2), "Pan"));
}
}
);
}
public static void main(String args[]) {
new TestDnD().setVisible(true);
}
}
// sample drag source component
class TestDrag extends javax.swing.JComponent {
javax.swing.JTextField theField;
TestDrag(javax.swing.JTextField f) {
theField = f;
setPreferredSize(f.getPreferredSize());
new TestDragSource(this);
}
String getText() {
return theField.getText();
}
public void paintComponent(java.awt.Graphics g) {
super.paintComponent(g);
g.setColor(java.awt.Color.pink);
g.fill3DRect(0,0,getWidth(),getHeight(),true);
g.setColor(java.awt.Color.black);
java.awt.FontMetrics fm = getFontMetrics(getFont());
g.drawString("DRAG ME",2,2+fm.getMaxAscent());
}
}
class TestDragSource implements java.awt.dnd.DragSourceListener, java.awt.dnd.DragGestureListener {
TestDragSource(TestDrag t) {
field = t;
java.awt.dnd.DragSource dragSource = java.awt.dnd.DragSource.getDefaultDragSource();
dragSource.createDefaultDragGestureRecognizer(t, java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE, this);
}
public void dragGestureRecognized(java.awt.dnd.DragGestureEvent e) {
String text = field.getText().trim();
if (text == null) return;
System.out.println("dragging the text : " + text);
java.awt.datatransfer.StringSelection td = new java.awt.datatransfer.StringSelection (text);
//TransferableDataset td = new TransferableDataset(getDataset());
e.startDrag(java.awt.dnd.DragSource.DefaultCopyDrop, td, this);
}
public void dragDropEnd (java.awt.dnd.DragSourceDropEvent e) {
System.out.println("DragSource: dragDropEnd");
}
public void dragEnter (java.awt.dnd.DragSourceDragEvent e) {
//System.out.println("DragSource: dragEnter");
}
public void dragExit (java.awt.dnd.DragSourceEvent e) {
//System.out.println("DragSource: dragExit");
}
public void dragOver (java.awt.dnd.DragSourceDragEvent e) {
//System.out.println("DragSource: dragOver");
}
public void dropActionChanged (java.awt.dnd.DragSourceDragEvent e) {
System.out.println("DragSource: dropActionChanged");
}
private TestDrag field;
}
// sample drop target component
class TestDrop extends javax.swing.JComponent {
TestDrop() {
setDropTarget(new TestDropTarget(this));
}
private String theText = "";
void setText(String text) {
theText = text;
repaint();
}
/**
* Paints the map image and the viewport frame on top.
* @see java.awt.Container#paint
public void paint(java.awt.Graphics g) {
}
*/
public void paintComponent(java.awt.Graphics g) {
super.paintComponent(g);
java.awt.FontMetrics fm = getFontMetrics(getFont());
g.drawString("drop here:",2,2+fm.getMaxAscent());
g.drawString(theText,5,5+2*fm.getMaxAscent()+fm.getMaxDescent());
}
}
class TestDropTarget extends java.awt.dnd.DropTarget {
public TestDropTarget(TestDrop om) {
theTarget = om;
}
public void dragEnter (java.awt.dnd.DropTargetDragEvent e) {
System.out.println("dragEnter");
e.acceptDrag(java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE);
}
public void drop (java.awt.dnd.DropTargetDropEvent e) {
System.out.println("drop");
java.awt.datatransfer.Transferable tr = e.getTransferable();
try {
if (e.isDataFlavorSupported (java.awt.datatransfer.DataFlavor.stringFlavor)) {
e.acceptDrop (java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE);
//com.esri.data.Dataset dataset = (com.esri.data.Dataset) transferable.getTransferData(com.esri.ae.cat.TransferableDataset.TransferableDatasetFlavor);
System.out.println("dropped text is " + tr.getTransferData(java.awt.datatransfer.DataFlavor.stringFlavor));
String text = (String) tr.getTransferData(java.awt.datatransfer.DataFlavor.stringFlavor);
theTarget.setText(text);
e.dropComplete(true);
} else {
System.out.println ("Rejected");
e.rejectDrop();
}
} catch (java.io.IOException io) {
io.printStackTrace();
e.dropComplete(false);
return;
} catch (java.awt.datatransfer.UnsupportedFlavorException ufe) {
ufe.printStackTrace();
e.dropComplete(false);
return;
}
}
/*
public void dragExit (java.awt.dnd.DropTargetEvent e) {
System.out.println("dragExit");
}
public void dragOver (java.awt.dnd.DropTargetDragEvent e) {
//System.out.println("dragOver");
}
public void dropActionChanged (java.awt.dnd.DropTargetDragEvent e) {
System.out.println("dropActionChanged");
}
*/
private TestDrop theTarget;
}
(Review ID: 56659)
======================================================================
- duplicates
-
JDK-4269666 Kestrel-FCS-E:Drag and Drop on Windows platform causes app to freeze.
-
- Closed
-