Drag and Drop using Components[

Hi,
As anyone used Drag and Drop for components? I mean, allowing the user to drag and drop a component around a container? Just curious, so far from what I've seen, the only things that can be dragged/dropped are properties of a given object, such as 'text" from a JLabel.
thanks

IMHO, you don't need fancy drag and drop features to do that. Implementing MouseInputListener and listening for mouseDragged is a good start. Then setting the component's bounds depending on the location of the mouse at the mouseReleased event (wrt the starting offset) could be a good idea (if you're using absolute positioning, of course).
From there, it all depends on what you want it to look like during the "transfer". You could, for instance paint the component in a BufferedImage at the start of the D&D and then paint the image with transparency as the mouse is moving.
Camickr had an interesting post that might help you :
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=492100

Similar Messages

  • How do you drag and drop using mac laptop?

    how do you drag and drop using mac laptop?

      As said above, you can click down, ons use the other finger to drag the object.  I had turned on the setting to use three-finger drag, so you can drag objects with three fingers.  To change gesture settings, go to the system preferences>trackpad.  Here you can also see all of the gestures of Mac OS X.

  • Implementing drag and drop across components with drag image...

    Hey all,
    Finally got the hang of drag and drop. Not too hard, but a little time consuming. I found an article showing how to capture and drag a BufferedImage within a JTree. When you click and drag a node, it creates a BufferedImage of the node on screen and "ghosts" it a bit, which has a very appealing effect.
    However, when I try to drag this image to a JList component, it disappears. So I created the same affect in the JList component. Now you can drag the image from the tree to the list and vice versa. However, the problem is, the image does not "fly over" the borders of the two components (butted up against each other) with the mouse. The image seems to go under the borders, while the mouse floats above everything.
    What I would like to do is be able to drag the image all over the application, perhaps even the desktop in the case of a SDI application. I want to be able to see this image drag from my Java app over the Windows Explorer folder, just like how you can do that with Windows Explorer, dragging an image of the selected node into any app that supports the drop. I know we can handle the "transfer" data from explorer and vice versa, but how to be able to keep an image with the mouse?
    My best guess is somehow using the Glass pane, grabbing a ref to its BufferedImage (if that is even what is there), and drawing the dragged item in that pane. But, then, how will the image move over the desktop outside of the app, where a glass pane is not?
    Is there a way to draw on top of anything, anywhere, but still be able to redraw the background as the image moves with the mouse? There are times where the image may be big, so I don't want to have to capture the underlying screen as an image covering the size of the drag image to restore it as the drag image moves around.
    Thank you.

    We know cursors support some degree of transparence because they have shapes other than blocks.
    I've done some playing around with
    Toolkit.getDefaultToolkit().createCustomCursor(....);The sad news is, it seems that as soon as a pixel's alpha value is greater than 0, it automatically becomes 100% opaque.
    The best you can do, is to take your image, and divide it into a pixel-checkerboard, and set the alpha value of alternating pixels to 0.
    e.g.
    BufferedImage i = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
            int[] data = ((DataBufferInt)i.getRaster().getDataBuffer()).getData();
            boolean on = true;
            for (int z=0; z<data.length; z++)
                if (on)
                    data[z] = 0xffffffff;
                else
                    data[z] = 0x00000000;
                on = !on;
                if (z%32==0) on = !on;
            Cursor hazyWhite = Toolkit.getDefaultToolkit().createCustomCursor(i, new Point(0,0), "hw");

  • I have a 5th gen iPod Touch. I have made playlists in iTunes. I need to get them to the iPod. When I had a Classic, it was automatic. You could drag and drop using iTunes music to the playlist in iTunes and it would automatically sync to the Classic.

    I have a 5th gen iPoc Touch. In the past, with the Classic, I could drag and drop from my iTunes music to a Classic playlist through iTunes. Now, the playlist I create in iTunes doesn't show on the Touch. I have maybe 29 GB of music on my Touch. I have already created playlists in iTunes that have substantial amounts of songs in each. How can I get those playlists on the Touch without doing a total sync that wipes the iPod? Is there a way to do it?
    As well, I am noticing here that my 5th gen iPod doesn't show as a registered device. How do I register it?

    For how to sync see:
    iTunes: Syncing media content to iOS devices and iPod       
    Try syncing using the manual method                
    Managing content manually on iPhone, iPad, and iPod
    This may also help:
    Adjusting to iTunes 12

  • Drag and Drop using Windows Explo

    Hi, I have a Zen Touch 20GB with firmware upgraded to version 2..0. I understand that it is possible to drag and drop files using windows explorer to the mp3 player. However, whenever I try to copy a folder containing audio files I always get a error stating that I don't have the permission to copy the audio files. I am able to copy other non- music files well and I have administrati've rights. Is this problem due the fact that audio files must reside within the default Music folder within the mp3 player? Can anyone kindly help me on this issue? Thanks a lot.

    yes but there must be a folder for music only ex:
    ----------------------------------explorer------------------------------------------------
    file View edit tools HElp WINDOWS
    FOLDER ... FOLDER.... FOLDER
    hard.. dri'ves
    C:ICON... D:ICON... OR... F:ZEN
    OR.
    OTher
    .zen. ..pretend.. this ..is ..the ..icon
    -subfolders
    ... - .MUSIC. ... .DATA. .ROOT.
    .. you should
    .. drag ur music into music \ data goes in\ and right here im guessing
    \ data folder\ is were ur contacts are
    and yah //Message Edited by kickenchicken on 07--2006 09:54 PM

  • Macbook pro won't drag and drop using mountain lion

    Since installing mountain lion. I have been unable to drag and drop.selected items just stay stuck to the cursor and when positioned where they need to go the item will not drop. the only way to correct this seems to be by pressing escape command and the trackpad which then returns the item to its original position. this has only happened since I installed mountain lion OS X  it is getting very annoying. My model is a mid 2009 15 inch laptop MacBook Pro which has 8 GB of RAM, I have noticed that other people seem to have the same problem but have been using an installed item called LapLink display I do not this have,so this is not causing the problem. any help to resolve thiswould be much appreciated.

    I now seem to have solved the problem after reading various solutions. The one that works for me is to to put the laptop to sleep and on reawaking the machine works as it should.
    Grant

  • Drag and Drop using iterator in ADF 11.1.1

    I am looking for a workaround for the following problem.
    <af:componentDragSource> returns an incorrect dragComponent value when dropped on a dropTarget when container elements are generated by an iterator.
    Below is sample code:
    in jspx file:
                         <af:panelGroupLayout>
                             <af:outputText value="Drag object 1"/>
                             <af:componentDragSource discriminant="activity"/>
                             <f:attribute name="draggedActivity" value="Drag object 1"/>
                         </af:panelGroupLayout>
                         <af:panelGroupLayout layout="horizontal" id="dropTarget1" inlineStyle="background-color:#ffff00">
                             <af:spacer height="8px"/>
                             <af:outputText value="Drop target 1"/>
                             <af:spacer width="600px"/>
                             <f:attribute name="dropTarget" value="Drop target 1"/>
                             <af:dropTarget actions="MOVE" dropListener="#{projectToolbarBean.narrativeBean.dropTest}">
                                 <af:dataFlavor flavorClass="javax.faces.component.UIComponent" discriminant="activity"/>
                             </af:dropTarget>
                         </af:panelGroupLayout>
                         <af:panelGroupLayout>
                             <af:outputText value="Drag object 2"/>
                             <f:attribute name="draggedActivity" value="Drag object 2"/>
                             <af:componentDragSource discriminant="activity"/>
                         </af:panelGroupLayout>
                         <af:panelGroupLayout layout="horizontal" id="dropTarget2" inlineStyle="background-color:#ffff00">
                             <af:spacer height="8px"/>
                             <af:outputText value="Drop target 2"/>
                             <f:attribute name="dropTarget" value="Drop target 2"/>
                             <af:spacer width="600px"/>
                             <af:dropTarget actions="MOVE" dropListener="#{projectToolbarBean.narrativeBean.dropTest}">
                                 <af:dataFlavor flavorClass="javax.faces.component.UIComponent" discriminant="activity"/>
                             </af:dropTarget>
                         </af:panelGroupLayout>
                         <af:panelGroupLayout>
                             <af:outputText value="Drag object 3"/>
                             <f:attribute name="draggedActivity" value="Drag object 3"/>
                             <af:componentDragSource discriminant="activity"/>
                         </af:panelGroupLayout>
                         <af:panelGroupLayout layout="horizontal" id="dropTarget3" inlineStyle="background-color:#ffff00">
                             <af:spacer height="8px"/>
                             <af:outputText value="Drop target 3"/>
                             <f:attribute name="dropTarget" value="Drop target 3"/>
                             <af:spacer width="600px"/>
                             <af:dropTarget actions="MOVE" dropListener="#{projectToolbarBean.narrativeBean.dropTest}">
                                 <af:dataFlavor flavorClass="javax.faces.component.UIComponent" discriminant="activity"/>
                             </af:dropTarget>
                         </af:panelGroupLayout>
                        <af:spacer height="16px"/>
                        <af:iterator var="item" first="0" varStatus="stat" rows="0"
                                  value="#{projectToolbarBean.narrativeBean.testDnD}">
                            <af:panelGroupLayout>
                                <af:outputText value="Drag object #{item}"/>
                                <af:componentDragSource discriminant="test"/>
                                <f:attribute name="draggedActivity" value="#{item}"/>
                            </af:panelGroupLayout>
                            <af:panelGroupLayout layout="horizontal" id="dropTarget1" inlineStyle="background-color:#ffff00">
                                <af:spacer height="8px"/>
                                <af:outputText value="Drop target #{item}"/>
                                <af:spacer width="600px"/>
                                <f:attribute name="dropTarget" value="#{item}"/>
                                <af:dropTarget actions="MOVE" dropListener="#{projectToolbarBean.narrativeBean.dropTest}">
                                    <af:dataFlavor flavorClass="javax.faces.component.UIComponent" discriminant="test"/>
                                </af:dropTarget>
                            </af:panelGroupLayout>
                         </af:iterator>In bean:
        public Collection getTestDnD() {
            List items = new ArrayList<Integer>();
            items.add(1);
            items.add(2);
            items.add(3);
            items.add(4);
            items.add(5);
            return items;
        public DnDAction dropTest(oracle.adf.view.rich.event.DropEvent event) {
            if (event.getDragComponent() != null && DnDAction.MOVE.equals(event.getProposedAction())) {
                UIComponent dropComponent = event.getDropComponent();
                UIComponent dragComponent = event.getDragComponent();
                String dropped = "";
                String dragged = "";
                if(dropComponent.getAttributes().get("dropTarget") instanceof String){
                    dropped = (String) dropComponent.getAttributes().get("dropTarget");
                    dragged = (String) dragComponent.getAttributes().get("draggedActivity");
                else if(dropComponent.getAttributes().get("dropTarget") instanceof Integer){
                   dropped = dropComponent.getAttributes().get("dropTarget").toString();
                   dragged = dragComponent.getAttributes().get("draggedActivity").toString();
                System.out.println("The label of the dragged object is: " + dragged + ". the drop target is " + dropped);
                return DnDAction.MOVE;
            } else {
                return DnDAction.NONE;
        }Drag a 'drag object' from the hard coded top group and drop it on a yellow drop target in the same group.
    Output from System.out will be correct.
    Do the same for the second iterator-generated group. You will find that the 'dragged' value in the bean code returns the same value as the 'dropped' value. In other words, event.getDragComponent() is losing context and is replaced by the value of event.getDropComponent().
    Can anyone help fix or workaround this problem? I cannot replace the iterator with a forEach due to other requirements.
    Does anyone know if this issue exists in ADF 11.1.2?
    Thanks

    Sorry 1 correction on my earlier post.  Install iTunes 12.0.1.26 for Windows (64-bit) - iTunes64Setup.exe (2014-10-16) NOT 12.1.0.71!
    Thanks Guys!  This fixed me up.
    I uninstalled
    - All  Apple Packages
    - Bonjour
    - iTunes
    - Quick Time packages
    Deleted the Apple, iTunes, & Quick Times folders:
    - c:\Program Files
    - c:\Program Files (x86)
    - C:\Program Data
    - C:\Users\%profile%\AppData\Local
    - C:\Users\%profile%\AppData\LocalLow
    - C:\Users\%profile%\AppData\Roaming
    Rebooted
    Sorry 1 correction on my earlier post.  Install iTunes 12.0.1.26 for Windows (64-bit) - iTunes64Setup.exe (2014-10-16) NOT 12.1.0.71!
    Installed the newest QuickTime 7.7.6
    and Bingo!  Hopefully the next iTunes release addresses the issue moving forward.
    Thanks Again!

  • Help needed with virtual bookshelf - drag and drop between components?

    Hi there,
    Im trying to create a virtual bookshelf, where book spines are individual movie clips that can be dragged and re-ordered on the shelf.  At the moment i can drag the spines to one assigned target, but not any target or 'nudge' the position of the other books along.
    Im sorry if this is a bit vague i'm not that experienced in as3, please feel free to ask any questions and i'll do my best to answer.  Im thinking that an array is necessary which holds the positions, but im not sure how to put it all together!
    Any help greatly appreciated! The code i have so far is:
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    var dragArray:Array = [red, blue, green, purple, yellow];
    var matchArray:Array = [target1, target2, target3, target4, target5];
    var currentClip:MovieClip;
    var startX:Number;
    var startY:Number;
    for(var i:int = 0; i < dragArray.length; i++) {
    dragArray[i].buttonMode = true;
    dragArray[i].addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
    matchArray[i].alpha = 0.2;
    function item_onMouseDown(event:MouseEvent):void {
    currentClip = MovieClip(event.currentTarget);
    startX = currentClip.x;
    startY = currentClip.y;
    addChild(currentClip); //bring to the front
    currentClip.startDrag();
    stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
    function stage_onMouseUp(event:MouseEvent):void {
    stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
    currentClip.stopDrag();
    var index:int = dragArray.indexOf(currentClip);
    var matchClip:MovieClip = MovieClip(matchArray[index]);
    if(matchClip.hitTestPoint(currentClip.x, currentClip.y, true)) {
      //a match was made! position the clip on the matching clip:
      currentClip.x = matchClip.x;
      currentClip.y = matchClip.y;
      //make it not draggable anymore:
      currentClip.removeEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
      currentClip.buttonMode = false;
    } else {
      //match was not made, so send the clip back where it started:
      currentClip.x = startX;
      currentClip.y = startY;

    Morning kglad, thanks for your help yesterday. I tried the code again and still have the same problems - you cant drop over another book and it nudges that book along aswell as the others to the right. Also if you drop a book back in its originally place - sometimes - it creates a gap next to it. The book still only seem happy in their original starting positions!
    Its very close, im continuing to try fiddle with it to get it working, have the whole of today to try and do this so the coffee is on!
    Ive taken some code out that I realise this morning I didnt't need - e.g the code that stops a book being dragged once you have positioned it (they need to be able to be repositioned more than once, and the code that sends a book back to its original position if you didnt reposition it over a target. If this was foolish please tell me! I have a feeling the latter was!
    so the code im trying to get working at the moment is:
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    var dragArray:Array = [red, blue, green, purple, yellow];
    var matchArray:Array = [target1, target2, target3, target4, target5];
    var currentClip:MovieClip;
    var startX:Number;
    var startY:Number;
    for(var i:int = 0; i < dragArray.length; i++) {
    // REMOVED
    //dragArray[i].buttonMode = true;
    dragArray[i].addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
    matchArray[i].alpha = 0.2;
    function item_onMouseDown(event:MouseEvent):void {
    currentClip = MovieClip(event.currentTarget);
    startX = currentClip.x;
    startY = currentClip.y;
    addChild(currentClip); //bring to the front
    currentClip.startDrag();
    stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
    function stage_onMouseUp(event:MouseEvent):void {
    stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
    currentClip.stopDrag();
    var index:int = dragArray.indexOf(currentClip);
    var matchClip:MovieClip = MovieClip(matchArray[index]);
    if(matchClip.hitTestPoint(currentClip.x, currentClip.y, true)) {
      //a match was made against a target:
      currentClip.x = matchClip.x;
      currentClip.y = matchClip.y;
    //REMOVED
    //make it not draggable anymore:
      //currentClip.removeEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
      //currentClip.buttonMode = false;
    for(var i:int=dragArray.indexOf(currentClip)+1;i<dragArray.length;i++){
    dragArray[i].x+=currentClip.width;
      // REMOVED
      //else {
      //match was not made, so send the clip back where it started:
      //currentClip.x = startX;
      //currentClip.y = startY;

  • Drag and Drop Swing Components between two different Application Windows

    Hi!!!
    I tried the Dnd feature using the DnD api. It was a simple test, where I ahd two different app windows each made up of a JLabel. One I registered as drag component and the other as a drop component. the drop componenet(JLabel) does not have any text making it invisble to the eyes. When I drag the other JLabel to the drop window, the drop JLAbel takes the text value. I was successful so far.
    But can I do the same for any other Swing component in a scenario where when I drag the component, the component should have physically moved into the other window.
    any help on this with sample code will be greatly apprciated.
    Thanks in advance
    Suja

    Ok I found the answer to your problem. If you download the tutorial they have the code there it's in one folder. I hope this helps.
    http://java.sun.com/docs/books/tutorial/

  • Imovie - how to import MP4 video clip for editing ? Wont drag and Drop ; using OSX on macbook

    the Video just flies back onto desktop.

    It should only have to do the full search the first time. From then on it should be quick.
    Since yours is not, I would suspect that iMovie is not able to write the results of the search, so the next time it has to start from scratch. This could be a permissions issue.
    Go to Disk Utility and try to repair permissions on your main hard disk.
    You might also try trashing preferences. (Details here - https://discussions.apple.com/docs/DOC-4061 )

  • ADF Button components: How to disable drag and drop [SOLVED]

    Hi everyone
    I need to develop an application which allows not the user to drag and drop button components. I've converted every single af:commandbutton to h:commandbutton, to prevent this behaviour, but a huge lot of other problems arose from this "solution". I'm using JDeveloper 10.1.3.3.0.4157, and I'm a beginner, so please be patient with me.
    Thanks in advance.

    Maybe I've drifted off-topic with this, but I found the way to achieve this. The only limitation is that the change must be done on the client's computer. The drag and drop feature can be disabled by going to the about:config page in Firefox, and setting nglayout.enable_drag_images to false. It can also be done in a more "portable" way by creating a user.js script in the profile folder and setting it from there. Thank you all for stopping by and reading.

  • More info on using drag and drop in AS3?

    I have coded a basic drag and drop using a rope .jpg saved as an mc. the idea is to have the user drag the rope from left to right using the mouse down and up functions. I was able to do this but I'm trying to add to the functionality by doing the following:
    dragging limited to a certain amount per drag
    no dragging up or down just left to right
    set boundries within the screensize
    I've looked and could only find as2 and basic tutes on this
    here is what I have so far
    any help?
    ropeclip_mc.addEventListener(MouseEvent.MOUSE_DOWN, ropedrag);
    ropeclip_mc.addEventListener(MouseEvent.MOUSE_UP, ropedrop);
    function ropedrag(e:MouseEvent):void
         ropeclip_mc.startDrag();
    function ropedrop(e:MouseEvent):void
         ropeclip_mc.stopDrag();
    RD

    Hi,
    Along with your code add this code to specify the dragging limited.
    var sbound:Rectangle = new Rectangle(x,y,width,height);
    x  states x position of the drag object starts.
    y  states y position of the drag object starts.
    width states width of the drag object.
    height states height of the drag object
    ropeclip_mc.startDrag(true,sbound);
    Try this.
    Saransoft

  • Drag and Drop, dropping to a parent component.

    I've been searching high and low for a solution to a problem without any success. I'm hoping someone here might have a suggestion.
    I have an application (written using Java 5.0) which allows dragging and dropping custom components between JPanels. My components themselves are JPanels with other components in them such as JTextFields. I've written custom TransferHandlers for my components and all works well. If I drag one of my components and drop it on the receiving panel, it works. If I drag and drop on an existing one of my components, the drop works since the components themselves don't support dropping (the drop is accepted by the parent JPanel).
    My problem occurs when I inadvertently do a drop onto a text component within one of my components. In this case the drop is rejected since the text component doesn't accept my Transferable. What I would like to happen is have the drop passed up to a containing panel that does accept the Transferable.
    I can't disable drop on the text components as I'd like them to still accept string drops.
    Is there another solution that will allow a parent (or more generally an ancestor) of a component to accept a drop rejected by a child component?

    "bmilesp" <[email protected]> wrote in
    message
    news:gnd5c7$jas$[email protected]..
    > hello,
    >
    > I've been searching on how to add drag and drop
    functionality to an hbox.
    > You're probably thinking "just use a tilelist", and
    that's what i'm
    > currently
    > using, but the tilelist cannot align items to the
    center, which is crucial
    > in
    > my application (if you need me to explain further i
    will, but i don't
    > think
    > it's relevant here).
    Sure it can.
    > So i need drag and drop on an Hbox. The repeater is
    necessary because the
    > hbox
    > may need to be populated with items initially, which can
    later be dragged
    > and
    > dropped either in itself (to re-arrange items) or into
    another hbox of
    > this
    > kind. For the past few hours I've been trying to find
    anything that can
    > even
    > hint at this type of functionality (i've been searching
    and experimenting
    > for
    > hours). If anyone can point me in the right direction,
    i'd appreciate it.
    > Thank
    > you very much. -b
    http://www.quilix.com/node/3

  • Drag and drop does not work in firefox 3

    Does anybody has the same issue with firefox when you add a layout to the oracle composer and you want to drag and drop some components that it just does not work...
    When i hoover over the title bar of a component i see the cross icon but the drag & drop does not work. WHen i do the same in IE8 or google chrome, it does work.
    I have this issue for both oracle composer stuff as for sites i build in webcenter spaces.
    We are working with the latest version of webcenter

    WebCenter is compatible with:
    * Firefox 2 & 3
    * Internet Exploirer 7 and 8
    * Safari 3.0
    It might be caused by a firefox extension in your browser.

  • Autoscrolling in a DropTarget (Drag and Drop)

    I have implemented Drag and Drop using DropTargets and a DragSource And DragGestureListener.
    The DropTarget I have is a customized JComponent. How can I make the DropTarget autoscroll for Drag and Drop events??

    Have you tried adding a MouseMotionListener to the target component and checking to see if the mouse coordinates are near the edge of the viewable area?

Maybe you are looking for

  • Which is better mac book pro or Mac book pro with retina display?

    which is better mac book pro or Mac book pro with retina display?

  • Update Mac remote desk top to 8.0.12

    i'm new to this I have remote desk top installed on my macbook and when I click on the icon i get the " what's new in 8.0.01" my question is how do i get the new release. 

  • Images for Spry Tabbed Widget  Buttons

    Hello, I would like my tab buttons to be images like the ones here: http://labs.wip3.adobe.com/technologies/spry/home.html It's the sample after this section: Spry 1.6.1-Ensuring Adobe AIR compatibiity Thanks, Troy

  • FMS 3.5 won't start

    So I just downloaded Flash media server 3.5 developmental so I can start live streaming for this website I am a part of. I installed with no problems(full instillation) restartes PC and every time I got to run the program.... Absolutely nothing happe

  • Why printer not connected message

    Plugged a dell 1720n laser printer into usb to print and got message that says "not connected".  Any ideas?