How to drag and drop a file with its Systemfile icon to a Jtext area

I want to drag and drop a file to a JText area with its system file icon , but the problem is I cant show the file icon.
Anyone knows this.
this is my code.
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.FileSystemView;
public class FileDrag extends JFrame implements DropTargetListener {
DropTarget dt;
File file;
JTextArea ta;
JLabel lbl;
Graphics g;
ImageIcon tmpIcon;
public FileDrag() {
super("Drop Test");
setSize(300, 300);
getContentPane().add(
new JLabel("Drop a list from your file chooser here:"),
BorderLayout.NORTH);
ta = new JTextArea();
ta.setBackground(Color.white);
getContentPane().add(ta);
dt = new DropTarget(ta, this);
setVisible(true);
public void dragEnter(DropTargetDragEvent dtde) {
System.out.println("Drag Enter");
public void dragExit(DropTargetEvent dte) {
System.out.println("Source: " + dte.getSource());
System.out.println("Drag Exit");
public void dragOver(DropTargetDragEvent dtde) {
System.out.println("Drag Over");
public void dropActionChanged(DropTargetDragEvent dtde) {
System.out.println("Drop Action Changed");
public void drop(DropTargetDropEvent dtde) {
FileSystemView view = FileSystemView.getFileSystemView();
JLabel testb;
Icon icon = null;
Toolkit tk;
Dimension dim;
BufferedImage buff = null;
try {
Transferable tr = dtde.getTransferable();
DataFlavor[] flavors = tr.getTransferDataFlavors();
for (int i = 0; i < flavors.length; i++) {
System.out.println("Possible flavor: " + flavors.getMimeType());
if (flavors[i].isFlavorJavaFileListType()) {
dtde.acceptDrop(DnDConstants.ACTION_COPY);
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++) {
System.out.println(list.get(j));
file = (File) list.get(j);
icon = view.getSystemIcon(file);
ta.append(list.get(j) + "\n");
ta.append("\n");
tk = Toolkit.getDefaultToolkit();
dim = tk.getBestCursorSize(icon.getIconWidth(), icon.getIconHeight());
buff = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(ta, buff.getGraphics(), 10, 10);
repaint();
dtde.dropComplete(true);
return;
System.out.println("Drop failed: " + dtde);
dtde.rejectDrop();
} catch (Exception e) {
e.printStackTrace();
dtde.rejectDrop();
public static void main(String args[]) {
new FileDrag();

I want to drag and drop a file to a JText area with its system file icon , but the problem is I cant show the file icon.
Anyone knows this.
this is my code.
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.FileSystemView;
public class FileDrag extends JFrame implements DropTargetListener {
DropTarget dt;
File file;
JTextArea ta;
JLabel lbl;
Graphics g;
ImageIcon tmpIcon;
public FileDrag() {
super("Drop Test");
setSize(300, 300);
getContentPane().add(
new JLabel("Drop a list from your file chooser here:"),
BorderLayout.NORTH);
ta = new JTextArea();
ta.setBackground(Color.white);
getContentPane().add(ta);
dt = new DropTarget(ta, this);
setVisible(true);
public void dragEnter(DropTargetDragEvent dtde) {
System.out.println("Drag Enter");
public void dragExit(DropTargetEvent dte) {
System.out.println("Source: " + dte.getSource());
System.out.println("Drag Exit");
public void dragOver(DropTargetDragEvent dtde) {
System.out.println("Drag Over");
public void dropActionChanged(DropTargetDragEvent dtde) {
System.out.println("Drop Action Changed");
public void drop(DropTargetDropEvent dtde) {
FileSystemView view = FileSystemView.getFileSystemView();
JLabel testb;
Icon icon = null;
Toolkit tk;
Dimension dim;
BufferedImage buff = null;
try {
Transferable tr = dtde.getTransferable();
DataFlavor[] flavors = tr.getTransferDataFlavors();
for (int i = 0; i < flavors.length; i++) {
System.out.println("Possible flavor: " + flavors.getMimeType());
if (flavors[i].isFlavorJavaFileListType()) {
dtde.acceptDrop(DnDConstants.ACTION_COPY);
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++) {
System.out.println(list.get(j));
file = (File) list.get(j);
icon = view.getSystemIcon(file);
ta.append(list.get(j) + "\n");
ta.append("\n");
tk = Toolkit.getDefaultToolkit();
dim = tk.getBestCursorSize(icon.getIconWidth(), icon.getIconHeight());
buff = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(ta, buff.getGraphics(), 10, 10);
repaint();
dtde.dropComplete(true);
return;
System.out.println("Drop failed: " + dtde);
dtde.rejectDrop();
} catch (Exception e) {
e.printStackTrace();
dtde.rejectDrop();
public static void main(String args[]) {
new FileDrag();

Similar Messages

  • How can i sync videos to my iphone 5 using Itunes 11. i also tried to convert the videos to mp4 and drag and drop the file in itunes but still i cant see videos in itunes library.

    how can i sync videos to my iphone 5 using Itunes 11. i also tried to convert the videos to mp4 and drag and drop the file in itunes but still i cant see videos in itunes library.

    Copied from this link.
    http://www.apple.com/iphone/specs.html
    Video formats supported: H.264 video up to 1080p, 30 frames per second, High Profile level 4.1 with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats; MPEG-4 video up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 Kbps per channel, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats; Motion JPEG (M-JPEG) up to 35 Mbps, 1280 by 720 pixels, 30 frames per second, audio in ulaw, PCM stereo audio in .avi file format
    There are 3rd party utilities available that "rip" content into a compatible format - most include an iPod and/or iPhone format selection. If a video plays in iTunes, iTunes includes an option to convert a selection for iPod/iPhone.

  • I download firefox 5.0 and now I'm having trouble dragging and dropping PDF files into Google Docs and I can't view the PDF once uploaded. I had no problems with this in the previous verion of Firefox

    With firefox 5.0 I can't drag and drop pdf files in the google docs screen. When I do eventually get a pdf file uploaded I can't view it. I get "no preview available". In my previous verion of firefox (4.something) I had no problems with this and I was able to drag and drop and after uploaded I could view the entire file.

    Thanks one again. I know you helped me the last to. I do have the Deja Vu font set in my folder. I downloaded and the last time. So I don't know if there is supposed to be more or not, but those were installed with Windows-XP after my reformat.
    This is really driving me nuts. as I've done several re-formats on my computer and several friends computers and even upgraded hardware so I am not necessarily a software or programming expert, I am somewhat advanced when it comes to computers in general and can usually diagnose the problem but these font's are the problem and they never were before.
    I did see in another forum that if you had a Dell Computer and did the Microsoft update for the onboard video card driver that it could be the culprit, but I have that disabled being I have a much better graphics card so the updates from Microsoft for the onboard video weren't installed.
    It' a Dell Dimension 3000 with an Intel(R) 82865G Graphics Controller so I don't believe it is the culprit being it is disabled. The actual video card that I am using is a PCI Nvidia GeForce 9400 GT with 1 GB Memory. And I didn't have any problem before.
    I appreciate the help. But still can't get things to work. Live Help Chat doesn't open for another two hours so maybe they can do "Remote Access" or something and can check setting and help me. But if you come up with other suggestions, they would be greatly appreciated.
    Thanks again.
    Susan

  • I want to drag and drop a file to a JText area with its file icon

    I want to drag and drop a file to a JText area with its file icon , but the problem is I cant show the file icon.
    Anyone knows this.
    this is my code.
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.Transferable;
    import java.awt.dnd.DnDConstants;
    import java.awt.dnd.DropTarget;
    import java.awt.dnd.DropTargetDragEvent;
    import java.awt.dnd.DropTargetDropEvent;
    import java.awt.dnd.DropTargetEvent;
    import java.awt.dnd.DropTargetListener;
    import java.io.File;
    import javax.swing.*;
    import javax.swing.filechooser.FileSystemView;
    public class FileDrag extends JFrame implements DropTargetListener {
    DropTarget dt;
    File file;
    JTextArea ta;
    JLabel lbl;
    Graphics g;
    ImageIcon tmpIcon;
    public FileDrag() {
    super("Drop Test");
    setSize(300, 300);
    getContentPane().add(
    new JLabel("Drop a list from your file chooser here:"),
    BorderLayout.NORTH);
    ta = new JTextArea();
    ta.setBackground(Color.white);
    getContentPane().add(ta);
    dt = new DropTarget(ta, this);
    setVisible(true);
    public void dragEnter(DropTargetDragEvent dtde) {
    System.out.println("Drag Enter");
    public void dragExit(DropTargetEvent dte) {
    System.out.println("Source: " + dte.getSource());
    System.out.println("Drag Exit");
    public void dragOver(DropTargetDragEvent dtde) {
    System.out.println("Drag Over");
    public void dropActionChanged(DropTargetDragEvent dtde) {
    System.out.println("Drop Action Changed");
    public void drop(DropTargetDropEvent dtde) {
    FileSystemView view = FileSystemView.getFileSystemView();
    JLabel testb;
    Icon icon = null;
    Toolkit tk;
    Dimension dim;
    BufferedImage buff = null;
    try {
    Transferable tr = dtde.getTransferable();
    DataFlavor[] flavors = tr.getTransferDataFlavors();
    for (int i = 0; i < flavors.length; i++) {
    System.out.println("Possible flavor: " + flavors.getMimeType());
    if (flavors.isFlavorJavaFileListType()) {
    dtde.acceptDrop(DnDConstants.ACTION_COPY);
    ta.setText("Successful file list drop.\n\n");
    java.util.List list = (java.util.List) tr.getTransferData(flavors);
    for (int j = 0; j < list.size(); j++) {
    System.out.println(list.get(j));
    file = (File) list.get(j);
    icon = view.getSystemIcon(file);
    ta.append(list.get(j) + "\n");
    ta.append("\n");
    tk = Toolkit.getDefaultToolkit();
    dim = tk.getBestCursorSize(icon.getIconWidth(), icon.getIconHeight());
    buff = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
    icon.paintIcon(ta, buff.getGraphics(), 10, 10);
    repaint();
    dtde.dropComplete(true);
    return;
    System.out.println("Drop failed: " + dtde);
    dtde.rejectDrop();
    } catch (Exception e) {
    e.printStackTrace();
    dtde.rejectDrop();
    public static void main(String args[]) {
    new FileDrag();
    }

    This appears to be a long-standing bug:
    https://bugzilla.mozilla.org/show_bug.cgi?id=634720
    and the accepted workaround is stated in comment 11.
    Oddly, it's possible to do the reverse, i.e. drag multiple eml files from Explorer to a TB folder.

  • Can anyone tell me how to drag and drop music to my ipod with the new version of itunes?

    yeah, so this new update *****.
    just hoping someone can tell me how to drag and drop my music onto my ipod like we used to be able to do in the old versions of itunes. THANKS!

    I haven't used it myself, but I've heard about this app.
    http://plumamazing.com/mac/iwatermark
    The are also a bunch in the App store.
    Matt

  • I just downloaded the new version of iTunes 10 and now it won't let me drag and drop any files from my computer.

    I just downloaded the new version of iTunes 10 and now it won't let me drag and drop any files from my computer into my iTunes. It lets me play the song from the folder in my computer and then it opens with iTunes and plays the song all the way through, but then if I try to play it again, it says the file cannot be located. So then I go to locate and go to the folder and all that and select it and nothing happens.

    Not sure whether for instance you initially had a Yahoo optimised version of Firefox, and have now overwritten it with an official Mozilla version. Although the Mozilla version should NOT add unwanted features, but the Yahoo version may well do.
    If you merely need to find the Yahoo emails page quickly just add it as a bookmark or as a bookmark on the Bookmarks toolbar and make sure that is visible.
    Clicking the star icon on the location bar whilst looking at your emails will bookmark the page.
    * [[How to use bookmarks to save and organize your favorite websites]]
    * [[Bookmarks Toolbar - Display your favorite websites at the top of the Firefox window]]
    I do not use Yahoo myself,and am not sure what add-ons are available. You could search yourself using
    * FirefoxButton -> add-ons
    ** see [[Find and install add-ons to add features to Firefox]]
    ** examples [https://addons.mozilla.org/en-us/firefox/addon/yahoo-toolbar/ yahoo toolbar] & [https://addons.mozilla.org/en-us/firefox/addon/yahoo-mail-notifier/ mail notifier]
    * also look at Yahoo's own information such as http://help.yahoo.com/tutorials/toolbar/cl3/c3_ff_toolbar1.html

  • How to drag and drop between portlets?

    Howdy!
    Could someone please be kind enough to show me how to drag and drop data between portlets. I want to select an icon, drag it to an application and launch the file associated with the icon in the application.
    I can do it within a portlet with some js functions but when I try it between portlets (on the same page)I see the forbiden sign.
    Thanks
    Jeff Graber

    Hi
    thanks for the advice. However, that is what I had done. Here is the code in the jsp file for the destination portlet and it does not work. If you have any ideas, thanks!
    <%@ page language="java" contentType="text/html;charset=UTF-8"%>
    <%@ taglib uri="netui-tags-databinding.tld" prefix="netui-data"%>
    <%@ taglib uri="netui-tags-html.tld" prefix="netui"%>
    <%@ taglib uri="netui-tags-template.tld" prefix="netui-template"%>
    <netui:html>
    <head>
    <title>
    MS Word Portlet
    </title>
              <script language="JavaScript" src="../js/common.js"></script>
              <script language="JavaScript" src="../js/containers.js"></script>
              <script language="JavaScript" src="../js/document.js"></script>
    </head>
    <body>
    Application Village Portlet
    <p>TextOre
    | <a id="MS Word" ondrop="sendInfo(this.id)" ondragover="fnCancelDefault()"><img src="/Jime/images/WORDY.gif" alt="Drag one or more documents here to open with MS Word" border="0"></img></a>
    | <a id="MS Excel" ondrop="sendInfo     (this.id);" ondragover="fnCancelDefault()"><img src="/Jime/images/EXCELY.gif" alt="Drag one or more documents here to open with MS Excel" border="0"></img></a>
    | <a id="MS PowerPoint" ondrop="sendInfo(this.id);" ondragover="fnCancelDefault()"><img src="/Jime/images/PowerPointY.gif" alt="Drag one or more documents here to open with MS PowerPoint" border="0"></img></a>
    | <a id="Trash" ondrop="sendInfo(this.id);" ondragover="fnCancelDefault()"><img src="/Jime/images/trashcan.gif" alt="Drag one or more documents here to delete" border="0"></img></a>
    </body>
    </netui:html>

  • How to drag and drop another swf or fla into a template?

    I am building a flash website for a friend. We are using templates he purchased at flashden.net.
    I normally use wordpress, joomla and other such systems and am familiar with html, php, cgi and such.
    This is my first time dealing with a flash template.
    I have downloaded the trial version of the software and he wants to purchase adobe flash professional for me
    So that we can edit the template and add features he wants in the future.
    The website that sells the templates says you can easily drag and drop addons to templates in flash
    but I am not finding it so easy. Is there somewhere online where I can find a tutuorial on how to step by step
    drag and drop flash files into another template etc.?
    Also, where can I find good tutorials in general? I have downloaded adobe flash for dummies it is not as indepth as I need
    to get a handle on this software.
    Thank you to anyone that offers me any advice,
    David Doherty

    Ned,
    Thank you for responding.
    Flashden.net does claim its a simple drag and drop operation to do this but they have little to know information on the site about the subject and
    having difficulty with the sellers on step by step instructions. They claim it's easy it may be.
    The person I am building the website for had a bad experience with one of the sellers who refused to offer anything but basic instructions and claimed the cost of the software was not worth his time.
    Here are the instructions that were provided:
      Open news_rotator.fla
      Go to library.
      Select and copy NewsRotator movie clip.
      Paste it into your own project’s library.
      Now, you can drag and drop it into your own movie clips.
      Use news.xml to add/remove headlines.
    As you can see from what your telling me this is insufficent information on how to drag and drop this flash into another flash template.
    I will attempt to contact other selers at flashden for information as I have other flash templates we have purchased.
    Thank you,
    David Doherty

  • Why cant i drag and drop mp3 files into my itunes library in itunes 11.1.1?

    I recently lost a hard drive with most of my music on it. i removed and reinstalled itunes and set it to work on my other hard drive. i was able to drag and drop mp3 files that i had and put them into my library. After the latest updates, now it only gives my the cirlcle with the slash though it when i try, not sure what changed

    did you manage to fix your problem.
    i tunes 6 used to be great for me but i upgraded to 7 which wiped my i tunes and ipod. im back to ver 6 now but i cant drag files from my c drive to any playlists

  • I can't drag and drop mp3 files directly to my shuffle

    i have a ipod shuffle (2nd gen). i cant drag and drop mp3 files via itunes. it only allows me to put them into library and then sync it. but i dont want to sync, i just want to put mp3s directly into shuffle.
    thanks

    thanks for the patiance
    with my old ipod (ipod nano 1st gen) i could easily drag and drop my mp3s from windows explorer to ipod by using itunes. is it itunes new version problem so that i couldnt drag and drop manually, or ipod shuffle problem.
    thanks again.

  • I can't drag and drop word files to a folder

    I can't drag and drop word files to a folder. When I click and hold over a file, nothing happens. Normally it goes where I drag it.

    thanks for the patiance
    with my old ipod (ipod nano 1st gen) i could easily drag and drop my mp3s from windows explorer to ipod by using itunes. is it itunes new version problem so that i couldnt drag and drop manually, or ipod shuffle problem.
    thanks again.

  • Drag and drop several files

    Hi,
    I'm using iPhoto '11 (version 9.4.2) and when I try to drag and drop several files into a folder, it fails.
    Actually it just does nothing: the drag and drop icon is created with the accurate numbre of items in a red star, the folder blinks but when I release the mouse, nothing happens.
    It fails sometimes with 3 photos, sometimes with 30.
    What's more puzzling is that it sometimes works: if I drag and drop of a single photo it always works. And I'm sometimes able to drop 10 or more photos.
    I'm running on a macbook pro retina with lion (10.8.2).
    Any idea of logs I could look at for some informations, some errors messages?
    Thanks,
    Laurent.

    I guess it creates new photos, hence it modifies the timestamps whereas drag and drop does not.
    There are two kinds of metadata involved when you consider  jpeg or other image file.
    One is the file data. This is what the Finder shows. This tells you nothing about the contents of the file, just the File itself.
    The problem with File metadata is that it can easily change as the file is moved from place to place or exported, e-mailed, uploaded etc.
    Photographs have also got both Exif and IPTC metadata. The date and time that your camera snapped the Photograph is recorded in the Exif metadata. Regardless if what the file date says, this is the actual time recorded by the camera.
    Photo applications like iPhoto, Aperture, Lightroom, Picasa, Photoshop etc get their date and time from the Exif metadata.
    When you export from iPhoto to the Finder new file is created containing your Photo (and its Exif). The File date is - quite accurately - reported as the date of Export. However, the Photo Date doesn't change.
    The problem is that the Finder doesn't work with Exif.
    So, your photo has the correct date, and so does the file, but they are different things. To sort on the Photo date you'll need to use a photo app.

  • Set default import format when drag and drop sound file into multitrack view?

    I've looked around the preference panels but cannot find where to set the import settings for dragging and dropping sound files into multitrack view. Some of our computers have correct settings and others do not. Thanks for your help!
    G

    I should have been more specific, sorry... I mean bit depth and bit rate... On some machines this defaults correctly and on other machines it is wrong. Not sure how to set these to downconvert properly by default. Unless it automatically takes the format of the source file, in which case it's just been luck.
    Thanks,
    G

  • Can't drag and drop music files

    after recent update i can't drag and drop mp3 files into library like before or go file->add file to library

    Thanks for the quick response Sebastian.
    Yeah, I know I can find the file in finder, but I used to be able to organize all my files in the iTunes interface and easily drag them to my project in AE CS3... so much more convenient.
    I tried .aif and .wav files, all formats that AE accepts. Like I mentioned, I used to do this with AE CS3 and my Windows OS... I was just wondering if this was a Mac bug or something. Not the end of the world, but it's little things like this I waste half a day on trying to figure out!! lol.

  • Mail doesn't attach files through dragging and dropping the files!

    Help please,
    Mail doesn't attach files through dragging and dropping the files on OS X ML, it crashes for a while !!

    Open Disk Utility and Repair disk permissions on the First Aid tab.
    Then, Restart and boot into Recovery Mode by holding down cmd-r on restart until you see a gray screen. When the Mac boots, you will be presented with some options. Choose Disk Utility and select your Hard drive volume (Macintosh HD is the default name). Then, on the First Aid tab, click Repair Disk (not permissions).
    If that doesn't help, you could try installing the 10.8.2 combo updater from the Apple Downloads site:
    http://support.apple.com/kb/DL1581

Maybe you are looking for