-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.1
-
x86
-
windows_nt
Name: krT82822 Date: 05/28/99
When using drag-n-drop aware components for datatransfer in an application,
using the exact same components in an inline Applet no DropTarget events will be
recieved. If a Frame is opened from the Applet to layout the same containers all is
nice and dandy.
This is a simple example to demonstrate the problem (it is actually
a rip of the DnD-example in the Java tutorial)
---- begin DnDbug.java
import java.awt.*;
import java.awt.dnd.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.io.*;
public class DnDbug extends JApplet {
class DraggableLabel extends JLabel implements
DragSourceListener, DragGestureListener {
DragSource dragSource;
public DraggableLabel(String s) {
super (s);
dragSource = new DragSource();
dragSource.
createDefaultDragGestureRecognizer(this,
DnDConstants.ACTION_COPY, this);
}
public void dragGestureRecognized(DragGestureEvent e) {
StringSelection text =
new StringSelection(getText());
dragSource.startDrag(e,
DragSource.DefaultCopyDrop,
text,
this);
}
public void dragDropEnd (DragSourceDropEvent e){}
public void dragEnter (DragSourceDragEvent e){}
public void dragExit (DragSourceEvent e){}
public void dragOver (DragSourceDragEvent e){}
public void dropActionChanged (DragSourceDragEvent e){}
}
class DroppableList extends JList
implements DropTargetListener {
DropTarget dropTarget;
Vector v = new Vector();
public DroppableList() {
dropTarget = new DropTarget (this, this);
}
public void dragEnter (DropTargetDragEvent e){
System.err.println("dragEnter");
e.acceptDrag (DnDConstants.ACTION_COPY);
}
public void dragExit (DropTargetEvent e){
}
public void dragOver (DropTargetDragEvent e){
System.err.println("dragOver");
}
public void drop (DropTargetDropEvent e){
System.err.println("drop");
try {
Transferable tr = e.getTransferable();
if (tr.isDataFlavorSupported (
DataFlavor.stringFlavor)) {
e.acceptDrop
(DnDConstants.ACTION_COPY_OR_MOVE);
String s = (String)tr.getTransferData (
DataFlavor.stringFlavor);
v.add (s);
setListData (v);
paintImmediately(getVisibleRect());
e.getDropTargetContext().dropComplete(true);
} else {
System.err.println ("Rejected");
e.rejectDrop();
}
} catch (IOException io) {
io.printStackTrace();
e.rejectDrop();
} catch (UnsupportedFlavorException ufe){
ufe.printStackTrace();
e.rejectDrop();
}
}
public void dropActionChanged (DropTargetDragEvent e) {
}
}
public void init() {
getContentPane().add(new DnDPanel());
}
class DnDPanel extends JPanel {
public DnDPanel() {
setLayout(new BorderLayout());
DraggableLabel north = new DraggableLabel("One");
DraggableLabel south = new DraggableLabel("Two");
DraggableLabel east = new DraggableLabel("Three");
DraggableLabel west = new DraggableLabel("Four");
DroppableList list = new DroppableList();
JScrollPane pane = new JScrollPane (list);
add (north, BorderLayout.NORTH);
add (south, BorderLayout.SOUTH);
add (east, BorderLayout.EAST);
add (west, BorderLayout.WEST);
add (pane, BorderLayout.CENTER);
setSize (300, 300);
}
}
public static void main(String[] args) {
DnDbug bug = new DnDbug();
Frame f = new Frame();
f.add(bug.new DnDPanel());
f.addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.setVisible (true);
}
}
---- end DnDbug.java
If the class is run as an application from the command line, all
works well. However if one tries to run if in Applet mode:
---- begin DnDbug.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>Bug</title>
</head>
<body>
<h1>Test</h1>
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="120"
height="100"
codebase="http://java.sun.com/products/plugin/1.2/jinstall-12-win32.cab#Version=1,2,0,0">
<param name="code" value="DnDbug.class">
<param name="codebase" value=".">
<param name="type" value="application/x-java-applet;version=1.2">
<COMMENT>
<EMBED type="application/x-java-applet;version=1.2" width="120"
height="100" align="baseline" code="DnDbug.class"
archive="."
pluginspage="http://java.sun.com/products/plugin/1.2/plugin-install.html"
>
<NOEMBED>
No JDK 1.2 support for APPLET!!
</NOEMBED>
</EMBED>
</COMMENT>
</object>
<hr>
</body> </html>
---- end DnDbug.html
...no drop*-events will be recieved.
To be able to DnD in an inline Applet
is a feature on which a current project of ours relies heavily,
so we'd really need this fixed!
(Review ID: 63138)
======================================================================
Name: krT82822 Date: 05/28/99
When I add a JPanel that handles dnd to a JFrame and run as an appliation drag and drop works great, but when I add the same panel to an applet no drops are accepted. I get only the no drop symbol?
//This class works fine. (The DropPane class is just a JPanel with a dropListners, which handles various drop flavors)
import javax.swing.*;
import java.awt.*;
import java.util.List;
import java.net.URL;
import java.awt.dnd.*;
public class DnDApplication extends JFrame
{
DnDApplication()
{
setSize(500,500);
DropPane dropPane = new DropPane( new DropHandler() );
dropPane.setBackground(Color.red);
dropPane.setPreferredSize(new Dimension(500,500));
setContentPane(dropPane);
}
class DropHandler implements FileDropHandler
{
public void handleFileDrop(List list){}
public void handleTextDrop(String s){}
public void handleURLDrop (URL url){}
}
static public void main(String args[])
{
DnDApplication app = new DnDApplication();
app.pack();
app.show();
}
}
//Doing the same thing with an applet does not work?
import javax.swing.*;
import java.awt.*;
import java.util.List;
import java.net.URL;
import java.awt.dnd.*;
public class DnDApplet extends JApplet
{
public void init()
{
setSize(500,500);
DropPane dropPane = new DropPane( new DropHandler() );
dropPane.setBackground(Color.red);
dropPane.setPreferredSize(new Dimension(500,500));
getContentPane().add(dropPane);
}
class DropHandler implements FileDropHandler
{
public void handleFileDrop(List list)
{
System.out.println("Successful Drop");
}
public void handleTextDrop(String s){}
public void handleURLDrop (URL url){}
}
}
>//Typing java -version
>java version 1.2.1
>HotSpot VM (1.0fcs, mixed mode, build E)
>
>
>//Typing java -fullversion
>java full version "JDK-1.2.1-A"
(Review ID: 83591)
======================================================================
- duplicates
-
JDK-4225247 Drag-and-Drop does not work in an applet on Windows NT
-
- Closed
-