Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4217433

Transferable.getTransferData() throws java.io.IOException

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.2.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_nt

      Description



      Name: vi73552 Date: 03/04/99




      I want to make a tree that accepts text dropped into it. I build
      and run my example app. I bring up the wordpad windows app,
      highlight some text and drag it into the tree in the jaja app.
      An exception is thrown.

      java.io.IOException: class java.awt.datatransfer.UnsupportedFlavorException:Plain Text caught while getting Data

      at java.awt.dnd.DropTargetContext$TransferableProxy.getTransferData(DropTargetContext.java:270)

      at TreePanel.drop(TreePanel.java:74)

      at java.awt.dnd.DropTarget.drop(DropTarget.java:343)

      at sun.awt.windows.WDropTargetContextPeer.processDropMessage(WDropTargetContextPeer.java:941)

      at sun.awt.windows.WDropTargetContextPeer.run(WDropTargetContextPeer.java:472)

      at javax.swing.SystemEventQueueUtilities.processRunnableEvent(SystemEventQueueUtilities.java:354)

      at javax.swing.SystemEventQueueUtilities.access$0(SystemEventQueueUtilities.java:350)

      at javax.swing.SystemEventQueueUtilities$RunnableTarget.processEvent(SystemEventQueueUtilities.java:391)

      at java.awt.Component.dispatchEventImpl(Component.java:2376)

      at java.awt.Component.dispatchEvent(Component.java:2289)

      at java.awt.EventQueue.dispatchEvent(EventQueue.java:258)

      at java.awt.EventDispatchThread.run(EventDispatchThread.java:68)


      In my drop() method I have these two lines of code.

         if (trans.isDataFlavorSupported(DataFlavor.plainTextFlavor))
            obj = trans.getTransferData(DataFlavor.plainTextFlavor);

      isDataFlavorSupported() returns true so I procede to getting the
      data. But getTransferData() throws an exception even though the
      previous call just returned true.


      Here's my complete example.
      **************************************************************
      import java.awt.event.*;
      import javax.swing.*;
      import java.awt.dnd.*;
      import java.awt.datatransfer.*;
      import java.awt.event.*;
      import java.io.*;



      public class TreePanel
      implements ActionListener, DropTargetListener
      {
      TreePanelUI view;
      JTree tree;
      DropTarget target;

      public TreePanel()
      {
      view = new TreePanelUI();
      tree = view.tree;
      view.closeButton.addActionListener(this);
      target = new DropTarget(tree, DnDConstants.ACTION_COPY, this);
      target.setActive (true);
      }

      JPanel getView()
      { return view; }

      public void actionPerformed(ActionEvent evt)
      {
      if(evt.getActionCommand().equals("Close"))
      System.exit(0);
      }

      public void dragEnter (DropTargetDragEvent dtde)
      {
      System.out.println ("dragEnter");
      DataFlavor df[] = dtde.getCurrentDataFlavors();
      if (dtde.isDataFlavorSupported(DataFlavor.plainTextFlavor))
      dtde.acceptDrag (DnDConstants.ACTION_COPY);
      else
      dtde.rejectDrag ();
      }

      public void dropActionChanged(DropTargetDragEvent dtde)
      { dragEnter(dtde); }

          public void dragOver (DropTargetDragEvent dtde)
      { System.out.println ("dragOver"); }

      public void dragExit (DropTargetEvent dte)
      { System.out.println ("dragExit"); }

      public void drop (DropTargetDropEvent dtde)
      {
      dtde.acceptDrop (DnDConstants.ACTION_COPY);

      System.out.println ("dropped");

      Transferable trans = dtde.getTransferable();
      Object obj = null;

      try
      {
      if (trans.isDataFlavorSupported(DataFlavor.plainTextFlavor))
                   obj = trans.getTransferData(DataFlavor.plainTextFlavor);

      System.out.println(obj);
      if (obj != null && obj instanceof InputStream)
      {
      InputStream input = (InputStream) obj;
      StringBuffer str = new StringBuffer();
      byte[] buffer = new byte[64];
      int count = input.read(buffer);
      while (count != -1)
      {
      str.append (new String (buffer, 0, count));
      count = input.read(buffer);
      }
      input.close();
      //text.setText (str.toString());
      }
      } catch (Exception e) { e.printStackTrace(); }
      finally
      {
      try { target.getDropTargetContext().dropComplete(true); }
      catch (Exception ignore) {}
      }
      }
      };

      ************************************************************
      import javax.swing.*;
      import java.awt.event.*;

      public class TreeTest
      implements ActionListener
      {
      public static void main(String args[])
      {
      System.out.println(System.getProperty("java.version"));
      JFrame frame = new JFrame("JDK 1.2");
      TreePanel panel = new TreePanel();
      frame.getContentPane().add(panel.getView());
      frame.setSize(300, 200);
      frame.show();
      }

        public void actionPerformed(ActionEvent e)
        { System.exit(0); }
      }
      *********************************************************
      import javax.swing.*;
      import java.beans.*;
      import java.awt.*;

      public class TreePanelUI extends javax.swing.JPanel
      {
      public TreePanelUI()
      {

      //{{INIT_CONTROLS
      setLayout(new BorderLayout(0,0));
      setSize(300,270);
      add("Center",JScrollPane1);
      JScrollPane1.setBounds(0,0,300,235);
      JScrollPane1.getViewport().add(tree);
      tree.setBounds(0,0,297,232);
      JPanel1.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
      add("South",JPanel1);
      JPanel1.setBounds(0,235,300,35);
      closeButton.setText("Close");
      JPanel1.add(closeButton);
      closeButton.setBounds(116,5,67,25);
      //}}

      //{{REGISTER_LISTENERS
      //}}
      }

      //{{DECLARE_CONTROLS
      javax.swing.JScrollPane JScrollPane1 = new javax.swing.JScrollPane();
      javax.swing.JTree tree = new javax.swing.JTree();
      javax.swing.JPanel JPanel1 = new javax.swing.JPanel();
      javax.swing.JButton closeButton = new javax.swing.JButton();
      //}}

      }
      (Review ID: 48238)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dmendenhsunw David Mendenhall (Inactive)
                Reporter:
                vasya Vassili Igouchkine (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: