JList Drag and Drop issues

I am having a weird problem. I have a JList, and it has draggable elements in it. When i click and drag a selected item it drags jsut fine and DnD suceeds. when i try to drag an unselected item it fails, though the selection changes.
is there any way to change the selection and start draging with jsut hte one click?
thanks

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class TestJList extends JFrame {
    public TestJList() {
        initComponents();
    private void initComponents() {
        list = new JList();
        textarea = new JTextArea();
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle("Test JList: dragEnabled");
        list.setModel(new AbstractListModel() {
            String[] strings = { "One", "Two", "Three" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings; }
list.setDragEnabled(true);
list.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent evt) {
listMouseMoved(evt);
getContentPane().add(list, BorderLayout.WEST);
textarea.setBackground(new Color(255, 255, 204));
textarea.setBorder(new LineBorder(new Color(0, 0, 0)));
getContentPane().add(textarea, BorderLayout.CENTER);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
private void listMouseMoved(MouseEvent evt) {
int index = list.locationToIndex(evt.getPoint());
list.setSelectedIndex(index);
public static void main(String args[]) {
new TestJList().setVisible(true);
private JList list;
private JTextArea textarea;

Similar Messages

  • Mail attachment drag and drop issue

    Been facing serious mail attachment drag-and-drop issue since 10.8 (if not from 10.7) and was disappointed to find the same behaviour still in 10.9.
    When I drag and drop a picture file (from Finder for example) into a message window or onto the Mail.app Dock icon, the system's window management somehow gets confused: my next step is to click on the message window in order to start typing. However, the mouse click causes that very window to escape under all other open applications / windows. Further on, I dig under to find the escapee and click again: once more it escapes. This can go on for a few annoying rounds until gets solved in an unexplainable way. This behaviour in not consistent, but has happens in about 8 cases out of 10.
    Apart from Mail.app I do not experience drag and drop issues of any kind.
    Anyone else suffering from this?

    I'd be interested in the answer to this too.
    It only just started happening to me a day or so ago, about the time that I think I did an OS upgrade.
    I'm on OSX 10.8.2.
    Its annoying.
    I can drop and drag in Finder but it just affects email.

  • Drag and Drop issue from Explorer folder to Music Library

    Hello
    I just updated my iTunes to 8.0.0.20 but something unexpected happened. I can’t drag and drop anymore songs from an explorer folder into my music library when my view mode is set to Grid (Album, Artist, Genre or Composer).
    When I try I have a kind of interdiction circle under my pointer.
    I can only perform this operation in list mode view. Few hours ago it was still possible to perform it but not after I updated. I reinstalled my iTunes but the problem persists.
    I have read the forums I know I can add to my playlist as usual by using the menu. But is it possible to get drag and drop operation when I drags song directly from a folder on my explorer window?
    It would be very appreciated if someone has an answer. I really messed up my library trying to fix this

    I fixed the drag and drop issues I had! Turns out they were caused by the permission problems of Vista. To fix it I just made sure all the files in the iTunes folder and sub folders were full control by my account.
    Make sure you check the properties of the iTunes database specifically because before, the iTunes folder had the correct permissions but they hadn't actually been inherited correctly by the iTunes DB files. Hope this helps anyone else.

  • Drag and drop issue alternatives

    Hello
    i'm having the same drag and drop issue as the other guys here. basically cant drag and drop to the desktop. Im looking for a workaround that doesnt involve making temporary backups or repairing iphoto libraries. My library is 260gb and even though it is being backed up i dont have a spare 260gb.

    That does not exist - the workaround (maybe permanent solution - who knows) is
    File menu ==> export
    And BTW if you are not backingup all the time you are 100% guarenteed to lose all of your files and photos sooner or later
    LN

  • Drag and Drop issue in Jlist - Transferhandler not working

    Hi all,
    I have a problem associated with the drag and drop of components into a Jlist.
    When I drag component out of a Jlist, the control reaches inside transfer handler, but when I try to insert a component into the Jlist, the control does not reach inside Jlist transfer handler.
         jlist.setDropMode(DropMode.INSERT);
         jlist.setDragEnabled(true);
         jlist.setTransferHandler(new TransferHandler()
                   List fileList;
                   boolean export = false;
                   List<File> newList = null;
                   protected Transferable createTransferable(JComponent c)
                        System.out.println("inside handler");
                                    ..............................Please help me with this issue.
    Any help in this regard will be well appreciated with dukes.
    Regards,
    Anees

    AneesAhamed wrote:
    Hi all,
    I have a problem associated with the drag and drop of components into a Jlist.
    When I drag component out of a Jlist, the control reaches inside transfer handler, but when I try to insert a component into the Jlist, the control does not reach inside Jlist transfer handler.
    jlist.setDropMode(DropMode.INSERT);
    jlist.setDragEnabled(true);
    jlist.setTransferHandler(new TransferHandler()
                   List fileList;
                   boolean export = false;
                   List<File> newList = null;
                   protected Transferable createTransferable(JComponent c)
                        System.out.println("inside handler");
    ..............................Please help me with this issue.
    Any help in this regard will be well appreciated with dukes.If you're wondering why your createTransferable() method is not called when you drag from some other component and drop into the list it is because createTransferable() is called when you start dragging. So it would be the TransferHandler of the source component, not your target list, that has its createTransferable() called in that case.
    When the list is the target of a drag&drop you should see the canImport() method of your TransferHandler being called. Do a System.out(0 in that method as well and see if that is the case.

  • Drag and drop issue, please help.

    I can no longer drag and drop photos within photoshop elements 12.  When working with a layer, I want to move it to a layer within another existing file, and no longer have the option.  The only way I have fixed the issue in the past is uninstall and reinstall the program.  I've read other forum posts and followed the instructions by resetting preferences and it does not work.
    Does anyone have any solutions to this issue?  Please help!

    With both files open, simplest to tile them side by side, you should be able to drag the layer from the source file onto the target file. So long as it shows the 'grasping hand' you can release the mouse and it should add the layer to the target.
    So what is happening now on your system? When you drag the layer to the target what icon is shown - 'grasping hand', 'no entry', something else?
    Cheers,
    Neale
    Insanity is hereditary, you get it from your children
    If this post or another user's post resolves the original issue, please mark the posts as correct and/or helpful accordingly. This helps other users with similar trouble get answers to their questions quicker. Thanks.

  • JList - drag and drop

    Hi,
    I'm struggling with getting my program outfitted with a drag and drop function in and between a few JList components. (I'm using NetBeans IDE 6.7)
    I have four JLists of which only one I want to enabled drag and drop rearrangement of the strings. Furthermore I would like to enable dragging from the other three lists into the rearrangeable list (which may be empty!).
    I've searched for answers but I just can't manage to translate the answers on other forums into a usable solution for my program... I am relatively new to Java and NetBeans, so I would appreciate if you could keep the answers simple... (if possible).
    What I know about this problem already:
    - if i set dragEnabled to true, I can drag text into e.g. a TextField without further complications

    JTextComponents have preinstalled TransferHandlers that make it possible to simply call setDragEnabled(true) and you are good to go. However, with most other components, you need to install a custom TransferHandler (ie call list.setTransferHandler() ) to get the job done.
    Here is a sample of the code you need: ListTransferHandler
    ICE

  • Wacky Drag and Drop issue with JNLP

    I'm sure I'll have to be a bit more descriptive but I'll just throw this out and see if anyone has any suggestions.
    I've got a swing app which is an administration tool to a rules engine I have built. I distribute the app to users using JNLP 1.2.
    Here's the problem. When I launch the app using JNLP, a portion of the app does not work. There is a panel in which I allow users to drag items off of a tree and onto a panel. They can drag and drop one item but when they attempt to drag and drop a second item it doesn't drop. If I take that same code which is being distributed via JNLP, copy it to the local machine and run it, it works. I can drag and drop all day long.
    There are no exceptions, no errors or funny gooey state things going on. I start the drag, the mouse pointer changes, I hover of the drop zone and let go of the mouse and it appears to drop, but the component does not show. Wacky.
    Does this set off any bells to anyone?
    Thanks,
    - Jay
    App compiled using 1.4.1_01.

    Ah ha.. Yes this does seem to the issue. Thanks for the response. I've tested it on a couple of machines and it works on the one's with 1.4.1 and it doesn't seem to work on 1.4.0 jre machines.
    NEW Question though, if I set my .jnlp to:
    <j2se version="1.4.1+"/>
    I get the 'ol 'Error Code 11 (11 Could not locate requested version'
    Is there any way to get this guy to auto-install???
    I've installed JRE 1.4.1 manually and it doesn't seem to pick that up either.
    Thanks...

  • Preview Drag and Drop Issue

    I use preview in school a lot. Converting lectures to PDF is a lot easier to use and i us a program called iFlash to make flash cards.
    What I want to do is use the text tool to highlight sections of text, drag them to the flash card window and then drop the text there. This is a really quick and easy way to make the flash cards.
    This works except when i click back to the card all the text that i dragged is deleted.
    Does anyone else have this issue. I have checked, this feature (highlight and drag...) works well in other programs (mail, pages) but not with my flash card program.
    Any ideas?

    I have checked, this feature (highlight and drag...) works well in other programs (mail, pages) but not with my flash card program.
    That suggests that the problem is with iFlash. Will it accept drags from other programs, besides Preview? If not, it probably doesn't support drag and drop at all. If it does, then its implementation is probably buggy, and you should contact the developer.

  • About Drag and drop issue

    As title, i am a newbie to flash using ActionScript 2.0 , and currently i enounter the problem with drag and drop coding. Below is my code:
    function dragSetup(clip, targ, position) {
    clip.onPress = function() {
    startDrag(this);
    clip.x +=2;
    clip.swapDepths(clip.x);
    clip.onRelease = clip.onReleaseOutside=function () {
    stopDrag();
    if (eval(this._droptarget) == targ) {
    this.onTarget=true;
    gotoAndStop(position);
    } else {
    this.onTarget=false;
    gotoAndStop(position);
    clip.myHomeX=clip._x;
    clip.myHomeY=clip._y;
    clip.onEnterFrame = function() {
    if(this.onTarget)
              this._x-=(this._x-this.myHomeX)/5;
              this._y-=(this._y-this.myHomeY)/5;
    function dragSetup2(clip, targ, correct) {
    clip.onPress = function() {
    startDrag(this);
    clip.x +=2;
    clip.swapDepths(clip.x);
    clip.onRelease = clip.onReleaseOutside=function () {
    stopDrag();
    if (eval(this._droptarget) == targ) {
    clip._visible = false;
    this.onTarget=false;
    gotoAndStop(correct+1);
    } else {
    this.onTarget=false;
    gotoAndStop(correct);
    var frame:Number = 1;
    dragSetup2(flexibleTxt, questionBox, frame);
    dragSetup(transparentTxt, questionBox, frame);
    dragSetup(blueTxt, questionBox, frame);
    dragSetup(TIRTxt, questionBox, frame);
    dragSetup(TRTxt, questionBox, frame);
    dragSetup(ssmTxt, questionBox, frame);
    dragSetup(siliconTxt, questionBox, frame);
    dragSetup(silicaTxt, questionBox, frame);
    dragSetup(silicateTxt, questionBox, frame);
    dragSetup(infraTxt, questionBox, frame);
    dragSetup(radioTxt, questionBox, frame);
    dragSetup(lightTxt, questionBox, frame);
    dragSetup(copperTxt, questionBox, frame);
    dragSetup(gopTxt, questionBox, frame);
    dragSetup(liquidTxt, questionBox, frame);
    The scenario is , whenever correct mc was drag and drop on the target mc , it move to the next frame with new target mc(new question) , for example "questionBox2".
    By applying the code above, everything work fine but i would like that whenever i "throw" the answer mc (flexibleTxt, blueTxt etc) , i want it to slide or glide for little more distance, jz like how u throw a card in real life on a smooth surface.
    I also prefer that when draging it's "angle?" change according to the direction of draging. For example if u point ur finger on north side of a card and drag to the east, it's "angle?" will change according to the direction u drag, in this case, means east.
    I know my description seem abit complicated but i really someone can undestand and help me solve this issue.
    This is the link i reference to for the code above,but i modify it to my own preference :http://www.swinburne.edu.au/design/tutorials/P-flash/T-How-to-drag-and-drop-in-Flash/ID-37 /
    PS : can i attach my fla file in this forum? if can, why i cant found any attach button?

    I am having a similar but reverse problem: Under 10.5.2, when trying to push or pull files from my wireless MacBook Pro via my Airport Extreme base station to or from my wired G5 Power PC, files hang in mid copy then stall.
    The other way around -- working from the G5 -- I have no problem at all.
    This started with 10.5, but I'm not sure if it was .1 or .2 because I upgraded from 10.4 just recently and did the combined 10.5 updates all at once on both machines.
    Thanks

  • Drag-and-drop issue with Linux, KDE

    My application used to work fine, but when i tested it on Linux drag and drop stopped working.
    I used snippet that would take list of supported DataFlavors of Transferable and used for loop to find a javafilelist one. (isJavaFileListType()).
    Well, now, it does that flava scan, but it doesn't find javafilelisttype in the list!
    I tried to retrieve String, serializedobject.. no use. It throws and illegal action exception of DnD or something like that.
    Does anybody know what's wrong, or had similar issues? I use j2 of v 1.5.2
    I shall provide you with more info if it's something totally new.

    I'd be interested in the answer to this too.
    It only just started happening to me a day or so ago, about the time that I think I did an OS upgrade.
    I'm on OSX 10.8.2.
    Its annoying.
    I can drop and drag in Finder but it just affects email.

  • Drag and drop issues.  I'm not alone.

    So clearly I'm not the only one dealing with this, I've seen other topics with people running into this problem.
    All of a sudden last night I was unable to drag and drop stuff around, copy and past, run a new program and I have no Spotlight. I've restarted Finder, the whole Mac, reset the PRAM, and even rand DU and repaired the disk. Nothing. Stil can't do stuff on it, and it's starting to get on my nerves.
    Does anyone know of a solution to this? I've read many "temporary fixes" that haven't done anything for me.
    Thanks!

    Inaki wrote:
    So clearly I'm not the only one dealing with this, I've seen other topics with people running into this problem.
    All of a sudden last night I was unable to drag and drop stuff around, copy and past, run a new program and I have no Spotlight. I've restarted Finder, the whole Mac, reset the PRAM, and even rand DU and repaired the disk. Nothing. Stil can't do stuff on it, and it's starting to get on my nerves.
    When you say, "All of a sudden" what were you doing on the computer? Do you have any 3rd party software installed. Any recent installs?
    Does anyone know of a solution to this? I've read many "temporary fixes" that haven't done anything for me.
    Create a new user and see if the problem exists with the new user. If not, then you most likely have a corrupted .plist or other file.
    If the problem exists with the new user, then it's a deeper issue - more system related.
    Your topic is a bit misleading - you have multiple issues - spotlight and the inability to run a new program. Is it possible that this new program is the problem?
    Message was edited by: nerowolfe

  • JList drag and drop to reorder items

    I like to see a implementation of a JList supporting drag and drop to reorder items. The solution has to work with any object type in the datamodel.

    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.DefaultListModel;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.SwingUtilities;
    public class ReorderList {
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new ReorderList().makeUI();
       public void makeUI() {
          Object[] data = {"One", "Two", "Three", "Four", "Five",
             "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve"
          DefaultListModel model = new DefaultListModel();
          for (Object object : data) {
             model.addElement(object);
          JList list = new JList(model);
          MouseAdapter listener = new ReorderListener(list);
          list.addMouseListener(listener);
          list.addMouseMotionListener(listener);
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(200, 200);
          frame.add(new JScrollPane(list));
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
    class ReorderListener extends MouseAdapter {
       private JList list;
       private int pressIndex = 0;
       private int releaseIndex = 0;
       public ReorderListener(JList list) {
          if (!(list.getModel() instanceof DefaultListModel)) {
             throw new IllegalArgumentException("List must have a DefaultListModel");
          this.list = list;
       @Override
       public void mousePressed(MouseEvent e) {
          pressIndex = list.locationToIndex(e.getPoint());
       @Override
       public void mouseReleased(MouseEvent e) {
          releaseIndex = list.locationToIndex(e.getPoint());
          if (releaseIndex != pressIndex && releaseIndex != -1) {
             reorder();
       @Override
       public void mouseDragged(MouseEvent e) {
          mouseReleased(e);
          pressIndex = releaseIndex;     
       private void reorder() {
          DefaultListModel model = (DefaultListModel) list.getModel();
          Object dragee = model.elementAt(pressIndex);
          model.removeElementAt(pressIndex);
          model.insertElementAt(dragee, releaseIndex);
    }edit Reduced a few LoC
    Edited by: Darryl.Burke

  • Organizer Drag and Drop Issue

    In PSE4 I am in Folder Location view working in Folder A. I drag and drop a few files to Folder B. Unfortunately now PSE puts me in Folder B. "I" didn't want to go to Folder B, I just wanted to put some files there. Other programs don't change the focus to the new folder. How can I get PSE4 not to do that?
    Thanks for any help.
    Dale

    Colin is right, but I have also been very frustrated by the behavior you mention, Michael. Thanks for that tip.
    Here is the weirdest thing. I am in Folder Location view and I have selected Folder 20070501 in the lefthand pane. On the right hand pane a band shows with that name followed by only one of the 97 pictures in the folder. Then comes a band by the name of the next directory and instead of showing any of the pictures actually in that directory, it shows a couple of pictures that are actually in the 2007501 directory. And so on it continues. Finally, the next directory in order is listed followed by the pictures actually in the 20070501 directory. It is nothing short of bizarre.
    HOWEVER, when I did what you suggested, Michael, everything was as it should be when I came back. So this seems to be just another variation of what you mentioned.
    Colin, you said you don't use Folder View much. Granted you can have pictures located anywhere and organize them with PSE4 but I've found for when I'm in Win Explorer and need to see something that having them organized by folders is helpful for me. Have either of you found a process for managing pictures that works well for you, because I'm still looking for the best way to do it including when to remove pictures from my hard drive.
    Dale

  • Album Artwork Drag and Drop issue

    Good morning all,
    After struggling with this last evening for some time I have decided it's time to ask the pros.
    In iTunes I used to be able to drag and drop album artwork. So, for instance, I would just go and google the album image I was looking for and then take that jpg and drop it in to whichever album is missing that particular cover on the main album screen.
    What seems to be happening now though is that iTunes thinks every jpg I try to drag over is actually a podcast and it takes that album cover and places it under "Podcasts"
    I know I could just go into the album properties and add the album art that way but this was just so much simpler.
    Any thoughts? Writing this in a hurry as well so please let me know if I need to be more specific.
    Thanks
    Chu

    That does not exist - the workaround (maybe permanent solution - who knows) is
    File menu ==> export
    And BTW if you are not backingup all the time you are 100% guarenteed to lose all of your files and photos sooner or later
    LN

Maybe you are looking for

  • Is it possible to obtain the last IP address from which the device has displayed a message from Find My iPhone ?

    Hello, a couple of months ago my macbook got stolen so when yesterday i recieved an email my message was displayed on it i was wondering if there is a possibility to get the last IP address used on that machine .So if there is such possibility could

  • How to Impove PDF Color Printing

    Thanks to previous help when my printer went awol and wouldn't print anything from PS, the great suggestion was made here to try PDF. For the small emergency at the time, it workded just great, and I could  print borderless.    However, that was just

  • Simple client - proxy - server toy program

    Hi. I haven't done many cs courses yet, lately i am reading on some introduction to network programming, and i thought i should create a simple toy program to test a bit. Essentially i'd like to keep the communication between client and server using

  • Change First Load and Menu Disappear with scroll

    Hello, Im in a crossroad trouble and think that one of my problems is that i can resolve it changying the first load of my site and relink to one anchor link. My other problem is that i want to recreate the behavior of the menu of this web http://www

  • Damaged iPhone 5

    Hi I really don't know where to start from, but ill try to cut it short. My name is Dan, I live in Israel. We don't really have Apple support in here. Even tough we have a Apple Premium Reseller and Israel cellular providers have contracts with Apple