Drag into TreeView

Hello everyone,
I want to make an easy application where you have a tree and on the other side three images. In this example I used three rectangles each one with a different color.
The user should be able to drag one of the rectangles to a tree item in order to add a new subitem.
Everything is working, the only problem I have is that I also be able to drop anywhere in the whole tree "frame". I want that the user is only allowed to release over
a tree item, not anywhere in the treeframe.
My second question is, can I also drag the whole image / rectangle instead of this small windows standard box when a user tries to drag something? I read that this
would be possible in JavaFX 8, there you are able to pass a whole image to the dragboard. My goal was to set the opacity of the draged rectangle to 20% and then stick
the rectangle to the mouse and if the user release the mouse, the rectangle should go back to its orignal position with the full opacity. That would be a "nice to have", but
the first problem is kind of important.
This example should work out of the box:
package de.hauke.edi;
import java.io.IOException;
import de.cargosoft.edi.eservicemanager.Main3.ModuleTreeItem;
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.image.ImageView;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Callback;
import javafx.util.Duration;
public class Main4 extends Application {
    @Override
    public void start(Stage primaryStage) throws IOException {
        BorderPane border = new BorderPane();
        Scene scene = new Scene(border, 700, 700);
        // setup tree
        TreeView<String> tree = new TreeView<String>();
        TreeItem<String> rootItem = new TreeItem<String>("Root");
        rootItem.setExpanded(true);
        for (int i = 1; i < 6; i++) {
            TreeItem<String> item = new TreeItem<String>("Node" + i);
            rootItem.getChildren().add(item);
        tree.setRoot(rootItem);
        // setup boxes
        final Rectangle red = new Rectangle(100, 100);
        red.setFill(Color.RED);
        final Rectangle green = new Rectangle(100, 100);
        green.setFill(Color.GREEN);
        final Rectangle blue = new Rectangle(100, 100);
        blue.setFill(Color.BLUE);
        addDragFunction(red, "red");
        addDragFunction(green, "green");
        addDragFunction(blue, "blue");
        tree.setCellFactory(new Callback<TreeView<String>, TreeCell<String>>() {
            public TreeCell<String> call(TreeView<String> arg0) {
                final TreeCell<String> treeCell = new TreeCell<String>() {
                    protected void updateItem(String item, boolean empty) {
                        super.updateItem(item, empty);
                        if (item != null) {
                            setText(item);
                treeCell.setOnDragOver(new EventHandler<DragEvent>() {
                    public void handle(DragEvent event) {
                        event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
                        event.consume();
                treeCell.setOnDragDropped(new EventHandler<DragEvent>() {
                    public void handle(DragEvent event) {
                        Dragboard db = event.getDragboard();
                        if (db.hasString()) {
                            TreeItem<String> item = new TreeItem<String>("New "+db.getString() + " colored element dropped");
                            treeCell.getTreeItem().getChildren().add(item);
                            treeCell.getTreeItem().setExpanded(true);
                        event.consume();
                return treeCell;
        // add elements to stage
        VBox vbox = new VBox();
        vbox.getChildren().add(red);
        vbox.getChildren().add(green);
        vbox.getChildren().add(blue);
        border.setLeft(tree);
        border.setRight(vbox);
        primaryStage.setScene(scene);
        primaryStage.show();
    private void addDragFunction(final Rectangle control, final String code) {
        control.setOnDragDetected(new EventHandler<MouseEvent>() {
            public void handle(MouseEvent event) {
                Dragboard db = control.startDragAndDrop(TransferMode.ANY);
                /* put a string on dragboard */
                ClipboardContent content = new ClipboardContent();
                content.putString(code);
                db.setContent(content);
                event.consume();
        control.setOnDragDone(new EventHandler<DragEvent>() {
            public void handle(DragEvent event) {
                event.consume();
    public static void main(String[] args) {
        launch(args);
Thanks for any help!

Everything is working, the only problem I have is that I also be able to drop anywhere in the whole tree "frame". I want that the user is only allowed to release over
a tree item, not anywhere in the treeframe.
Just surround the code in the handle methods for your setOnDragOver and setOnDragDropped handlers with
if ( ! treeCell.isEmpty() ) { ... }
You could add further logic here if you needed, e.g. to prevent the user dropping on the root or to limit the number of children dropped onto a single node.
For the JavaFX 8 image functionality with the drag, in your setOnDragDetected handler, change the opacity, create an image from the control by calling snapshot(), and pass the image to the Dragboard's setDragView(...) method. In the setOnDragDone handler, revert the opacity.

Similar Messages

  • IMessage no longer accepts images to be dragged into the message box

    My iMessage iMac app no longer accepts images to be dragged into the message box since upgrading to Mavericks. I used to be able to just drag in .jpg images and they would appear in the text field to be sent to another persons iPhone/iPad/iMac. This no longer happens and just ignores that I have dragged it. Not even a "not accepted" icon appears.
    Is this just me? Or a bug in Mavericks?
    James

    Its working again now after a restart so must be a bug.

  • Clips automatically lengthened when dragged into timeline

    Hello,
    I'm new to FCP X, just as I am with video editing so please forgive my noviceness!
    When I drag clips from the Event Library into the Timeline(?) (The bit at the bottom, where you arrange the clips) they are automatically made longer. For example, one clip has a length of 54 seconds in the event library, but when dragged into the timeline, it has been stretched to 56 seconds. I'm trying to match a band's studio recording footage to the finished audio and it is impossible when the clips are slowed down (and subsequently lower in pitch).
    Is there a setting I need to know about to prevent this? How can I fix this problem?
    Many thanks

    If you mark the 'In' and 'Out' points and then press the 'E' key, the clip should be added to the Timeline exactly as marked in the Event Library.
    Press 'Q' to add it above the Timeline as a Connected Clip at the Skimmer or the Playhead position.
    Press 'W' to insert it into the Timeline at the Skimmer or the Playhead position (all the other clips will be pushed along the timeline to make room for it).
    Press 'D' to overwrite it to the Timeline at the Skimmer or the Playhead position.
    If you try some of these options and the clip duration changes, I suggest you trash your preferences.
    Unexplained faults like this can often be fixed by clearing out FCP X's preferences (for some reason, they get knotted up from time to time).
    Download Digital Rebellion's Preference Manager (free, simple to use, and perfectly safe, both to download and use).
    http://www.digitalrebellion.com/prefman/
    With Preference Manager, you can backup the Prefs when FCP X (or any of the Apple Professional Applications) are working normally. Then when either of the applications are acting strangely, Trash the Preferences, then Restore from your backups (just a mouse-click).
    If you trash the prefs and don't restore them, you will need to manually restore all your FCP X settings again, so it's a great idea to backup Preferences from time to time when FCP X is working well, then your backups are up to date.
    Doesn't fix every problem, but it fixes a lot.
    Andy

  • I downloaded 5.0 but it isn't giving me the icon to drag into my application folder. I have a Mac. What to do? Thanks

    The download Firefox page said a Firefox icon would appear to drag into the Application folder and from there I should drag it onto my Icon bar. I downloaded 5.0 but no icon is appearing on my screen to drag to Applications? I have a Mac computer and have been running Firefox for quite some time. How do I get the down load into my Application folder and then onto my startup bar? Thanks

    See also:
    * http://kb.mozillazine.org/Installing_Firefox#Mac_OS_X
    * https://support.mozilla.com/kb/Installing+Firefox+on+Mac

  • Medium Name detail objects can't able to drag into WebI filter panel

    Hi experts,
    In our OLAP universes on SAP BI Query we have medium name detailed objects, which we are not able to drag into Web Intelligence filter panel. Whenever we try it says that you can't drag this object into filter panel.
    The exact message is "You can not use this object in the filter pane".  This is not applicable to all, some of Medium Name detail objects are allowed at filter pane.
    Can any one throw some light on this. why we can't use medium name detailed objects in WebI Report filter panel.
    Regards,
    Ravi Kumar Garre
    Edited by: Ravi Kumar Garre on Sep 21, 2009 3:21 PM

    Hi Ingo,
    Based on my analysis found that the property for Condition panel is disabled only for Medium Name detail objects when BI InfoObject having text enabled for Medium Name (only).
    In case of short and long text this property is enabled on integration with out any manual efforts.
    Are there any special considerations (like performance) for medium name detail objects in doing so. I mean using medium name details objects in Condition panel are we going to face any performance issues. Is it recommended to have medium name details objects as condition?
    Highly appreciate on your inputs.
    Regards,
    Ravi Kumar Garre

  • Software downloads mount drive but do not show icons to drag into applications folder

    I downloaded Flash this weekend and Logos 5 today. Both downloaded and the drives mounted, but the drives did not show the software package to be dragged into my application folder. In the case of Flash, the folder header was there, but the space below, where the Flash app was supposed to be was blank. In the case of Logos, when I opened the drive, the only thing visible was the arrow between the app and the shortcut to the applications folder. There was nothing to grab and drag either. Any ideas for me?

    3rd party software uses all kinds of different ways to get installed.
    Some provide installers you double click on inside the mounted .dmg.  And to keep things interesting, different vendors use different installer utilities
    Some include an Alias pointing at the Applications folder.
    Some just give you the App and you figure out what to do with it (if you are lucky, these sometimes include a README file that tells you want you should do).
    This is life outside the Mac App Store.

  • I download the new version. No Firefox icon appears to be dragged into the Applications folder. I am on a new Mac with the latest software.

    I downloaded the most recent version of Firefox as requested. No Firefox icon appears
    to drag into the Applications folder. I tried twice with no luck. The old version remains.
    I am on a new Mac. I will, when this works, be updating my older Mac as well.

    The thing in your download folder is a "disk image." You have to double-click it and it will place a white "disk" on your desktop. It should also open a window with a Firefox icon and your applications folder. Then you can drag it to the applications folder. When you are done drag that disk to the trash. More details in this article - [[Installing Firefox on Mac]]

  • Im unable to import an mp3 track into garageband. I used to be able to just click and drag into GB. Advice please?

    Im unable to import an mp3 track into garageband (version 08). I used to be able to just click and drag into GB. Advice please?

    Arch Blr wrote:
    Im unable to import an mp3 into garageband
    http://www.bulletsandbones.com/GB/GBFAQ.html#filewontimport
    (Let the page FULLY load. The link to your answer is at the top of your screen)

  • Hi, I have found my older ipod guessing 2nd in line from first generation. Music was on a PC, this tower is long gone but i still have my music on this older device. It opens in itunes but I cannot transfer of drag into my itunes library.

    Hi, I have found my older ipod guessing 2nd in line from first generation. Music was Downloaded from BearShare onto a PC, this tower is long gone but i still have my music on this older device. It opens in itunes on my mac laptop but I cannot transfer/send toor of drag into my itunes library. I can only listen to the music from the laptop. If I try to transfer songs to a laptop folder it copies in text. Any suggestions?

    The following user tip is worth checking through:
    Recover your iTunes library from your iPod or iOS device

  • After downloading music and dragging into iTunes I end up with multiple copies of the album on my hard drive. I do have the "copy files into iTunes library" checked. When I try to erase one of the copies I end up with red ! in iTunes library.

    Please Help!  After downloading an album and dragging it into itunes I end up having multiple copies of the album on my hard drive.  I do have (under Itunes preferences, advanced) copy songs into itunes library "checked".  I'm sure this is the reason for the multiple copies.  When I try to delete one of the copies of the album and go back to itunes and try playing a song, I get a red exclamtion point next to the song with an error message saying itunes cannot locate file. My questions are, Does Itunes literally make a copy of the song? If so , How do you know which file to delete?

    Sony's own entertainment software on the Vaio plays merry **** with iTunes, worse there's no telling when it will kick in.
    First head over to the Sony Vaio site and get the update for the software, that will stop it from messing with the iTunes database/library files when you connect your iPod.
    http://support.apple.com/kb/TS2715
    http://esupport.sony.com/US/perl/swu-download.pl?mdl=VGNP588EQ&updid=4526&osid=28
    With that stopped you can add the music back without fear of this happening again.

  • I've been using Iphoto as a primary download program for years. As of today, when I click a thumbnail to open the photo, I get a black screen with an exclamation mark on some shots. Also, these shots can't be dragged into Adobe Bridge. Would love help!

    I use Iphoto as my primary download tool, then drag images into Adobe Bridge. Just today, when I tried to open a photo by clicking a thumbnail, all I got was an image of an exclamation mark and I couldn't drag the shot either. These are images I've successfully opened and dragged before. I would love guidance from anyone who knows a fix for this. Thanks!  John

    The ! turns up when iPhoto loses the connection between the thumbnail in the iPhoto Window and the file it represents.
    What version of iPhoto?
    As Larry says, your workflow doesn't make a whole lot of sense. If you're using iPhoto only for downloading then you're best off using Image Capture (in your Applications Folder) and just keep the whole database element out if it. If you're using iPhoto also to organise, then what are you using Bridge for? Anything you do in Bridge - or Photoshop - is unavailable in iPhoto if you work this way.
    Regards
    TD

  • HELP-Songs can no longer be dragged into playlists on my Itunes

    I have noticed recently that I can no longer click and 'drag' my songs from my library play list, to other playlists on itunes. Is there another way I can transfer specific songs from the library to my playlists? Or is there a way I can fix it so I can continue to drag my songs from the library to other playlists?
    Thank you!

    Are you trying to drag songs to a regular or a smart playlist? You cannot drag songs to a smart playlist, instead you have to make the tags match the smart playlists conditions (or make the conditions match the tags). If you are having problems dragging to a regular playlist, try opening that playlist in a second window by double clicking on it, move it aside so you can see both iTunes windows, and try dragging the song from the Library into the playlist's window.

  • External hard-drive disappeared after dragging into Spotlight

    Dear users,
    My external hard-drive under devices  disappeared after I dragged it into Spotlight to reindex it to make it searchable.
    There was a cloud puff animation when i dragged it from the devices icon on the left of folders to the spotlight privacy box window.
    Please help. Thank you!

    Hi there,
    did you find out what the problem was or how to re-map the ext. HDD?
    I have the same problem.
    thank you.

  • Tab does not show when dragged into it's own new window

    This happened after I updated to Firefox 8.0.1. Same problem with 9.0.1. I'm on a Mac running OS X 10.5.8. I have not changed any add-ons, plugins, extensions, or anything like that.
    Every time a tab is dragged from my main window to form it's own new window, the tab button on the new window does not appear. I only have a + sign showing.
    A tab will show when I open a new tab, but the original "tab" does not appear. The + sign also appears on the left side of all new tabs. Isn't it supposed to be on the right?
    If I have 2 "tabs" open but only have 1 tab showing and try to close the window, Firefox asks me if I'm sure I want to close the 2 tabs.
    Tabs when opening blank new windows work properly. Dragging a tab to an already opened window works fine as well.
    Most of the time a tab is dragged out on accident, and it is quite annoying because I can't drag it back into the main window.
    Any help or suggestions would be greatly appreciated.
    Many Thanks!

    I found the cause but no solution, it's actually a plugin that does that: divx plus weblpayer (it gets installed when you install DivX on your system), if you disable it and restart firefox it all works again. But I want that plugin... so DivX need to fix this, unless it is a Firefox bug in its own core... anyway these two together creates the problem.
    (I'm running Firefox 9.x on OSX Lion)
    I also wish firefox tab tear out tab worked more like chrome's tab tear out, much friendlier...

  • Installed update of Firefox, but cannot drag into applications folder, it indicates that "The operation cannot be completed because you do not have sufficient privileges", so how can I complete the install?

    I try to drag the app into the applications folder where an old app of firefox exists and it asks me if I want to replace it and after i say yes it gives me the operation cannot be completed message.

    If there are problems with updating or with the permissions then easiest is to download the full version and trash the currently installed version to do a clean install of the new version.
    Download a new copy of the Firefox program and save the disk image (dmg) file to the desktop
    *Firefox 9.0.x: http://www.mozilla.org/en-US/firefox/all.html
    *Trash the current Firefox application to do a clean (re-)install
    *Install the new version that you have downloaded
    Your profile data is stored elsewhere in the Firefox Profile Folder, so you won't lose your bookmarks and other personal data if you uninstall and (re)install Firefox.
    *http://kb.mozillazine.org/Profile_folder_-_Firefox

Maybe you are looking for

  • Do I need to use a custom controller & view set

    Good Day, Please excuse the long question. I am in the process of creating a new BSP application.  In a nut shell, my application is going to accept a bunch of data in the URL and pass the data to an external system.  Depending on what is returned fr

  • Hyper-V Replication over Dedicated LAN and "is alive" checks over Corporate LAN

    I am testing Hyper-V replication to see if it will be a suitable replacement for the ArcServer RHA product.  One thing I am struggling with is configuring the replication to use the dedicated LAN, but still have the host servers verify over the corpo

  • BA activation - Error in Document level - cost center validaty date error

    Hi, We have activated business area for a perticular Cocode, The problem is, All the cost center were assigned to Business area from valid date 1.1.08, But when an entry is passed before the cost center validy date, that is if an entry is passed on 3

  • Date time in top of Dash board CC&B screen

    Hi, Apparently in 2.1, top part of the screen used to show the date/time. Its not coming in 2.3.1. How to include date/time in 2.3.1 screen ? Ideally it's a configuration setting we're missing. Thanks in advance

  • How to rerieve records from the table starting with character 'D'

    Hi Folks, How to get the records from the table starting with character 'D'. Select Max (fld1) fron tab1 into tab1-fld1 where fld 2 = l_fld2 and starting character of fld(1) is 'D'. last record in the table starting with character 'D' How can i do th