Drag file into JTextArea

Hi
i want to enable drag ability for JtextArea i.e. when a file is dragged onto the JtextArea the files contents are to be shown. I am new to Drag and Drop
public MyEditor()
          //Create the textArea and configure it.
          output = new JTextArea();
          output.setMargin(new Insets(5,5,5,5));
          output.getDocument().addUndoableEditListener(undoManager);
          output.getDocument().addDocumentListener(new MyTextAreaListener());
          dt = new DropTarget(output,new MyDropTarget());
class MyDropTarget implements DropTargetListener
        public void dragEnter(DropTargetDragEvent dtde)
        public void dragExit(DropTargetEvent dte)
        public void dragOver(DropTargetDragEvent dtde)
        public void dropActionChanged(DropTargetDragEvent dtde)
       public void drop(DropTargetDropEvent dtde)
            Transferable tr = dtde.getTransferable();
            DataFlavor[] flavors = tr.getTransferDataFlavors();
            if (flavors.isFlavorJavaFileListType())
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
ta.setText("Successful file list drop.\n\n");
java.util.List list = (java.util.List)tr.getTransferData(flavors[i]);
for (int j = 0; j < list.size(); j++) {
ta.append(list.get(j) + "\n");
dtde.dropComplete(true);
The contents of the method is wrong..public void drop(DropTargetDropEvent dtde)..can anyone help me. my problem is this code does not work

import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.util.HashMap;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.undo.*;
import java.awt.dnd.*;
import java.awt.datatransfer.*;
public class MyEditor extends JFrame
     private static final long serialVersionUID = 1L;
      * JTextArea
     public static JTextArea output;
      * HashMap
     private HashMap actions;
      * inputFile
     private String fileName;
      * Manager for UNDO operation
     private UndoManager undoManager = new UndoManager();
      * JScrollpane
     private JScrollPane scrollPane;
      * JFrame
      private static JFrame fr = new JFrame();
       * Drop Target
      private DropTarget dt;
      * create Menubar for the frame
     public MyEditor()
          //Create the textArea and configure it.
          output = new JTextArea();
          output.setMargin(new Insets(5,5,5,5));
          output.getDocument().addUndoableEditListener(undoManager);
          output.getDocument().addDocumentListener(new MyTextAreaListener());
           dt = new DropTarget(output,new MyDropTarget());
        scrollPane = new JScrollPane(output);
          scrollPane.setPreferredSize(new Dimension(600, 400));
        JLabel label = new JLabel("  ");
        fr.getContentPane().add(label, BorderLayout.SOUTH);
          fr.getContentPane().add(scrollPane, BorderLayout.CENTER);
        fr.addWindowListener(new MyWindowListener());
          //createActionTable(output);
          /*/Create menuitems
          JMenu fileMenu = createFileMenu();
          //Add menuItems to MenuBar
          JMenuBar mb = new JMenuBar();
          mb.add(fileMenu);
          mb.add(editMenu);
          mb.add(formatMenu);
          mb.add(searchMenu);
          fr.setJMenuBar(mb);*/
      * Get Name of Action from HashMap
      * @param name
      * @return Action
     private Action getActionByName(String name)
          return (Action)(actions.get(name));
      * Create the GUI and show it.  For thread safety,
      * this method should be invoked from the
      * event-dispatching thread.
     private static void createAndShowGUI()
          //Make sure we have nice window decorations.
          JFrame.setDefaultLookAndFeelDecorated(true);
           * Instance of this class
          MyEditor searcheditor = new MyEditor();
          //searcheditor.createMenuBar();
          fr.setTitle("Editor");
          fr.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
          fr.pack();
          fr.setVisible(true);
      * Main Method
      * @param args command Line Arguments
     public static void main(String[] args)
          javax.swing.SwingUtilities.invokeLater(new Runnable()
               public void run()
                    createAndShowGUI();
     class MyWindowListener implements WindowListener
        public void windowOpened(WindowEvent e)
        public void windowIconified(WindowEvent e)
        public void windowDeiconified(WindowEvent e)
        public void windowActivated(WindowEvent e)
        public void windowDeactivated(WindowEvent e)
        public void windowClosing(WindowEvent e)
            MyTextAreaStatus myob = new MyTextAreaStatus();
            boolean status = myob.getStatus();
            if(!status)
                int option = JOptionPane.showConfirmDialog(output,"File not Saved \n Do you want to close?","MyEditor",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
                if( option == JOptionPane.YES_OPTION)
                    System.exit(0);
                else
                    myob.setStatus(false);
            else
                System.exit(0);
        public void windowClosed(WindowEvent e)
    class MyTextAreaListener implements DocumentListener
        MyTextAreaStatus myob;
        public void changedUpdate(DocumentEvent e)
             System.out.println("Changed");
             boolean temp = false;
             myob = new MyTextAreaStatus();
             myob.setStatus(temp);
        public void insertUpdate(DocumentEvent e)
            System.out.println("inserted");
            boolean temp = false;
            myob = new MyTextAreaStatus();
            myob.setStatus(temp);
        public void removeUpdate(DocumentEvent e)
             System.out.println("Removed");
             boolean temp = false;
             myob = new MyTextAreaStatus();
             myob.setStatus(temp);
    class MyTextAreaStatus
         * booean to determine te status of textArea
        boolean currentStatus = true;
        public void setStatus(boolean tempStatus)
             System.out.println("temp Status is"+tempStatus);
             currentStatus = tempStatus;
             System.out.println("currentStatus is"+currentStatus);
        public boolean getStatus()
            System.out.println("status is"+currentStatus);
            return currentStatus;
    class MyDropTarget implements DropTargetListener
        public void dragEnter(DropTargetDragEvent dtde)
        public void dragExit(DropTargetEvent dte)
        public void dragOver(DropTargetDragEvent dtde)
        public void dropActionChanged(DropTargetDragEvent dtde)
        public void drop(DropTargetDropEvent dtde)
            try
                Transferable tr = dtde.getTransferable();
                DataFlavor[] flavors = tr.getTransferDataFlavors();
                for (int i = 0; i < flavors.length; i++)
                if (flavors.isFlavorJavaFileListType())
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
java.util.List list = (java.util.List)tr.getTransferData(flavors[i]);
for (int j = 0; j < list.size(); j++)
output.append(list.get(j) + "\n");
dtde.dropComplete(true);
catch(UnsupportedFlavorException use)
catch(IOException ioe)
here is a code that will work. trying dragging a file into the text area.Only the path appears.not the contents

Similar Messages

  • Can't Drag Files into the Itunes Library anymore

    I was just taking some mp3s from my old computer to my new one and I have been doing this for a few days, yesterday, I couldn't drag anymore songs into the library for some reason. A blue rectangle comes up, but I can't position it over 'Music'. Dragging files into the playlists still work though.
    Can anyone help?

    How to rip CDs with iTunes - http://www.macworld.com/article/156861/2011/01/howto_rip_cds.html
    Introduction to iTunes CD Ripping Settings - http://ipod.about.com/od/introductiontoitunes/ss/importsettings.htm

  • Can't drag files into the queue window on some computers

    For some reason, on my new desktop and my laptop. I cannot drag files into the Queue window in Media encoder. I  have tried dragging avi's, wav, and mp4. As the files I am dragging hover over the queue window, my mouse turns into the "circle with a line through it" pointer and I cannot add the files that way. I can click the plus sign and then browse to its location to add. I just want to have my drag n drop feature working again... Any ideas why i can on some computers and not others?
    I did try running media encoder as administrator. All my computers are running windows 8.1.

    do you have source patching turned on for audio?

  • All of a sudden, I am unable to click-and-drag files into folders?

    I have a 2012 Macbook Air 11". I was dragging files into folders and then all of a sudden I couldn't. All I can do is copy and paste...frustrating.
    I tried accessibility settings, enabling dragging but that didn't change anything. Any suggestions?

    Restart your Mac and try again.

  • Can't drag files into folders in PDF portfolio

    I have created a PDF portfolio that contains primarily PDFs converted from e-mail messages, along with a few files from various Microsoft Office products. The portfolio has been added to over time, and now we have almost 100 files in the portfolio, so we'd like to organize these files into folders so it is easier to use.
    However, when I create a folder, I am not able to drag any files into it. I've tried all different types of files--PDFs, Word, PowerPoint--when I drag the file on top of the folder, I get the circle backslash symbol indicating the function is not allowed. I can't find any information about this in the Help files; every tutorial I've looked at indicates that I should be able to drag and drop files wherever I like, but doesn't mention what to do if I can't.
    I'm using Acrobat Pro X on Windows XP with Service Pack 3.
    Any suggestions about why this might be happening and how to fix it would be greatly appreciated! I really don't want to have to recreate the whole thing, but it's not going to be very useful if we continue adding unorganized files.
    Thanks,
    Lisa

    I tried a different layout (I had a custom layout set up; I switched to the standard Grid), and I still can't drag and drop.
    I just now created a new portfolio with a few of the same files, and I was able to drag the files into a folder I created.
    Yes, the original portfolio was created in Acrobat 9.
    Thanks,
    Lisa

  • OS Lion: Can't drag attachments into Mail message, Can't drag files into Trash

    Dragging an attachment into a Mail causes a crash adn I have to force quit. I can attach files via the menu, but keep forgetting and have to keep force quitting.
    Also (probably not connected), I can't move files into the Trash... Just get a Moving "xxxx" to "Trash" dialog and the progress bar never changes...
    Have created a new User and the problem persists.
    Any ideas?
    Mac OS X Lion 10.7.3 (11D50)

    damnfool wrote:
    Have created a new User and the problem persists.
    Boot up holding command-r keys into Lion Recovery Volume. Reinstall Lion and it will "install in place" so none of your own data or settings should be effected.

  • ITunes 11.0.1: Can't drag files into playlist unless it's in "List" view mode

    If I drag and drop audio files from Finder into a playlist in iTunes 11 (which I do in order to make sure meta tags are correct), they only appear in the playlist if i'm using "List" mode. Using "grid" or "artist list", the files get added to my iTunes library, but they don't appear in the playlist I dragged them into.
    What's up with this? Is it happening for other people?
    (This is iTunes 11.0.1 on OS X 10.8.2.)

    berrrnard,
    I get the same result as you. Best advice ..... always drag them to the List.
    I don't really follow this though.......... (which I do in order to make sure meta tags are correct).
    What do you mean ??

  • Can't drag files into itunes from computer folder.

    Im running windows 7 64bit, with the newest version of itunes:10.2.2.14.  I can't drag files from my "music folder" which is in my documents into itunes anymore.  I used to be able to do this with my old computer running windows 7 32bit, and even on windows vista, but it doesn't seem to work for me now. is there a setting that i can change? or mess around with something to fix this problem?

    Ah. Just updated iPod again and movie dragged in fine.
    Odd how it should work for one and not the other.
    I guess that could a "bug fix" that the update referred to?

  • Lost ability to drag files into InDesign from Bridge

    Hi,
    I posted this in the Bridge section also as I'm not really sure on which end the problem is.
    All of a sudden I cannot drag files from Bridge into  InDesign CS4 anymore. It still works in Photoshop and Illustrator but not  InDesign. I cannot figure out what happened. Yesterday it worked and today it does not. Does anyone know what the  problem could be?
    I just did a test and if I try and drag from Bridge CS4 into InDesign CS3 it works. So the Problems seems to be only with InDesign CS4.
    Thanks.

    I called Adobe b/c this was driving me crazy. With  the program closed I had to hold down Shift+Ctrl+Alt - then start the  program and delete the preferences. That fixed this issue.

  • Finder crashes & restarts on dragging files into trash or emptying trash

    Today, for no reason that I can fathom, finder has started crashing and restarting whenever I drag a file into trash or empty the trash. I realise this is a variation on a theme, but nothing I do seems to affect it. It wasn't happening yesterday but just started today.
    Have created a new test user and they are also affected.
    I have tried the following (based on similar posts I have read):
    Deleting the .plist files (com.apple.finder and the equivalent sidebars)
    Repairing the disk & permissions
    reinstalling the 10.4.6 update
    interpreting the crash.log (not much sense to me I'm afraid)
    .Trash seems fine
    The problem is irritating, and as yet doesn't appear to warrant a complete clean install.
    Any ideas short of this would be gratefully received.
    Cheers
    Rob
    Imac Intel   Mac OS X (10.4.6)  

    Should I have deleted myself as Administrator and created a new Administrator identity, instead?
    Not delete your old admin account, just make a new admin account & try that one.
    I read on a different thread to try an Archive and Install. Is this a good option for me?
    10.5.x does an Atchive automatically by itself, in theory you won't loode anything, but without a backup, as well as a problem, there's no guarantee.
    Try this if you haven't...
    "Try Disk Utility
    1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
    *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
    3. Click the First Aid tab.
    4. Select your Mac OS X volume.
    5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214
    Then try a Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes.
    (Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.)

  • Lost ability to drag files into InDesign

    Hi,
    All of a sudden I cannot drag files from Bridge into InDesign anymore. It still works in Photoshop and Illustraor but not InDesign. I cannot figure out what happened. Does anyone know what the problem could be?
    I have to add this is CS4. But I just did a test and if I try and drag from Bridge into InDesign CS3 it works. So the Problems seems to be only with InDesign CS4.
    Thanks.
    Message was edited by: kit02

    I called Adobe b/c this was driving me crazy. With the program closed I had to hold down Shift+Ctrl+Alt - then start the program and delete the preferences. That fixed this issue.

  • How do you drag files into folders on the new mountain lion?

    When i select the file i want to drag into a folder, it drags normally but i can not place it in the new folder.  nothing fancy just rying to move pictures into the same folder.
    Thanks

    Hi there...
    I'm in the same boat.
    I clean installed Mountain Lion no problems, everything seems to be a little quicker even... .a bonus.
    But then I stumbled across something.
    I am unable to move or drag files around.
    Let's say I have a file jpg in the desktop, and I want to move it to the pictures folder... Normally I would just hold down the trackpad, and physically move it in to the open pictures finder... but it just will not move.  I can select it, open it, rename it, everything... but I just cannot drag anything anywhere.
    Lets say the jpg on my desktop needs work and I want to open it in Photoshop.  I have the Photoshop icon in my Dock, and for years have simply dragged whatever jpg onto the PHotoshop icon in the Dock to open it.. .but now I can't.
    At the moment I am copy/pasting everything, which is time consuming and sooo annoying you have no idea.
    I just wanted to move a AVI from my downloads to the desktop.  I had to copy, paste, then delete from downloads... ***?!?!
    Am I the only one experiencing this problem??
    Please let me know.

  • Sometimes I can't drag files into Sidebar folders... and then I can... etc.

    I cannot figure out what causes the erratic misbehavior of sidebar folders. At one point I'll easily drag a file or a folder from the same Finder window into a Sidebar folder, but moments later the sidebar folders simply won't spring open. But a few minutes later they will.
    Anyone got a tip?
    NB: I had this same misbehavior before I completely rebuilt my HD - I even zeroed to write over bad blocks, reinstalled OS & updated from Apple, gradually added my 3rd party apps by reinstalling each of them (whew!). I had figured that and some other (minor) glitchy behaviors were too little free space, bad block, some directory corruption, etc.

    Depending on the file, it may just take a minute to decide.
    Ray

  • Cant drag files into ID anymore, can only Place, why?

    CS4 and Win7...Generally when I work, I have one window open with all the files Im working with.  To open an ID file, or to drop a text or graphic into an open ID document, I would drag the file over into the ID area.  Since I restored my computer, It no longer lets me do this with anything.  I just get the "circle/slash" icon.  What is preventing me from doing this?  Was never aware of a setting that would prevent this.

    Have you tried to change the UAC (User Account Control) settings in Windows 7?
    Try to change, or even disable the UAC. You will find the settings for this in your Control Panel/System and Security.
    I dont think it is a InDesign problem.
    Also: If you are running Windows 7 x64 you should at least once start InDesign "as administrator". It does a lot of things behind that solves problems.

  • I suddenly cannot drag any files anywhere. I cannot drag files into other files. I cannot drag files into trash. There is no dragging going on. What do I do?

    I suddenly cannot drag and drop any files or documents. I cannot drag anything anywhere. I cannot drag into other files. I cannot drag into trash. There is no dragging going on. What do I do?
    I have already tried "safe reboot." Nope, didn't help.
    Help!!!

    Should I have deleted myself as Administrator and created a new Administrator identity, instead?
    Not delete your old admin account, just make a new admin account & try that one.
    I read on a different thread to try an Archive and Install. Is this a good option for me?
    10.5.x does an Atchive automatically by itself, in theory you won't loode anything, but without a backup, as well as a problem, there's no guarantee.
    Try this if you haven't...
    "Try Disk Utility
    1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
    *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
    3. Click the First Aid tab.
    4. Select your Mac OS X volume.
    5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214
    Then try a Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes.
    (Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.)

Maybe you are looking for

  • Email setting in nokia e 90

    hi,i would like to know the email setting in my nokia e 90 phone.

  • Scripting to load all pdfs in a month into the place command?

    Hello, I was wondering if anyone knows of a script that allows for you to place all pdfs within a set date range from a folder into an InDesign document? I am looking to do my monthly report and each month I have to go out and get each one, would be

  • Deploy differences between 904 standalone and 903 J2EE and Web cache versio

    I am trying to port an application from jboss (3.0.3) to OAS 9iAS rel2. Since the application uses local interfaces in the EJBs, I am using the pre-release versions of OAS. My development environment also include ant and xdoclet. I am not using JDeve

  • Error -1073807339

    Hello, I am new with Labview and I am currently trying to connect a Lecroy HDO6034 oscilloscope via USB to perform a data acquisition using a NI driver. I can see in NI MAX that the scope is connected to the computer but when I try to use a driver I

  • Adcmctl.sh: exiting with status 1

    Please enter a valid responsibility. The responsibility System Administrator does not exist or is not active. Check that the correct application short name is specified for your responsibility.