Drag the image into target

I need to drag the image like (banana.png) and drop that image into target(rectangle),target2(rectangle),etc. but I difficult to replace that target(rectangle) to be (banana.png) in drop event handler, Please help Me..
this is my source code
final Rectangle target = new Rectangle();
target.setOnDragDropped(new EventHandler <DragEvent>() {
@Override
public void handle(DragEvent event) {
System.out.println("onDragDrop");
Dragboard db = event.getDragboard();
if (db.hasImage()) {
db.getImage(); //how to get the image (banana.png) and replace the target (rectangle) ?
event.consume();
});

final Pane rectangleHolder = new Pane();
final Rectangle rectangle = new Rectangle();
rectangleHolder.getChildren().add(rectangle);
// add rectangleHolder to the layout instead of rectangle...
// and then
if (db.hasImage()) {
  rectangleHolder.getChildren().setAll(new ImageView(db.getImage());
}Depending on your layout, you may be able simply replace the rectangle in the existing layout without introducing the new Pane. You can always do something like
ObservableList<Node> rectangleAndSiblings = ((Pane)rectangle.getParent()).getChildren();
rectangleAndSiblings.set(rectangleAndSiblings.indexOf(rectangle), new ImageView(db.getImage()));but it doesn't need to be that complex.

Similar Messages

  • When dragging an image onto a fresh canvas, the resizing feature presnaps the image into the canvas size. I can confirm that this has not happened to me in previous projects. I've also tested this problem by making a new larger document size and dragging

    Contexts: I am very competent with GFX and have worked on many projects.
    When dragging an image onto a fresh canvas, the resizing feature presnaps the image into the canvas size. I can confirm that this has not happened to me in previous projects. I've also tested this problem by making a new larger document size and dragging in the same render. It snaps again. I don't want to re-size from the canvas dimensions, I want to resize from the render's original dimensions.

    Ap_Compsci_student_13 wrote:
    ok sorry but doesn't sscce say to post the whole code?the first S is Short, and yes, it needs to be all the code needed to illustrate the problem and let use reproduce it. If you were developing a new Web framework, your example might be short, but for a student game it's very long.

  • Using Pages 5.2.2: When I drag an image into my document, I lose the related text.  I can crop the image, make it smaller, but it is surrounded by blankness that overrides the text.  Help?!

    Using Pages 5.2.2, MacBook Pro, OSX 10.9.5:  I cannot drag an image into my document without it obliterating the text.  Even after re-sizing,  the image just becomes small inside a larger blank area that appears to cover the saved text.  Help?

    Using Pages 5.2.2, MacBook Pro, OSX 10.9.5:  I cannot drag an image into my document without it obliterating the text.  Even after re-sizing,  the image just becomes small inside a larger blank area that appears to cover the saved text.  Help?

  • Help!  I drag an image into pages but it gives me the images info instead of the picture!  What do I do?

    Does any one know what i need to change.  When i'm dragging an image into pages it ends up with the images info and web address rather than the image itself.  What should I do?
    Thank you.

    Try dragging the image to the desktop and then to the Pages document or
    Select and copy the image and paste it into the document.
    It could be that the webpage is making it impossible to knick the image. I have encountered that a few times.

  • Problem in saving the image into SQL database..

    Hello,
    In my application I have to save image file (say jpg) into the database and retrieve back and display it on the applet. I am through with grabbing the pixels of the image & sending the pixel array to the servlet but I am struck in how to store the image into the database and retrieve the same.
    Can anybody please help me in this regard... its really urgent...
    Thanks in advance
    Swarna

    Hello.
    I've been researching this problem (saving images in a MySQL database) in order to accomplish a task I was assigned to. Finally I was able to do it. I'd be glad if it will be of any use.
    First of all: the original question was related to an applet. So, the post from rkippen should be read. It says almost everything, leaving the code job for us. Since I managed to write some code, I'll put it here, but I'm not dealing with the byte transferring issue.
    To obtain a byte array from a file I'd open the file with FileInputStream and use a loop to read bytes from it and save them into a ByteArrayOutputStream object. The ByteArrayOutputStream class has a method named �toByteArray()� which returns an array of bytes (byte [] b = baos.toByteArray()) that can be transferred in a socket connection, as said by rkippen.
    My problem was to save an image captured by a web camera. I had an Image object, which I converted into a byte array and saved into the database. Eventually I had to read the image and show it to the user.
    The table in the MySQL database could be:
    CREATE TABLE  test (
      id int(11) NOT NULL auto_increment,
      img blob NOT NULL,
      PRIMARY KEY  (id)
    )I had problems trying to use the �setBlob� and �getBlob� methods in the Statement object, so I used the �setBytes� and �getBytes� methods . In the end, I liked these methods most because they where more suitable to my application.
    The database operations are:
        public int insertImage(Image image) throws SQLException {
            int id = -1;
            String sql = "insert into test (img) values (?)\n";
            PreparedStatement ps = this.getStatement(sql);  // this method is trivial
            byte [] bytes = this.getBytes(imagem); // * see below
            ps.setBytes(1, bytes);
            ps.executeUpdate();
            id = ps.getGeneratedKeys().getInt(0); //Actually I couldn't make this line work yet.
            return id;
        public Image selectImage(int id) throws SQLException {
            Image img = null;
            String sql = "select img from test where id = ?\n";
            PreparedStatement ps = getStatement(sql);
            ps.setInt(1, id);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                byte [] bytes = rs.getBytes(1);
                img = this.getImage(bytes); // * see below
            return img;
        }* If the bytes are read directly from a file, I think it is not necessary to convert it into an Image. Just send the bytes to the database method would work. On the other hand, if the image read form the DB will be written directly into files, the bytes obtained from rs.getBytes(1) would be enough.
    The image operations are:
        public byte [] getBytes(Image image) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ImageIO.write(this.getBufferedImage(image), "JPEG", baos);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            return baos.toByteArray();
        public Image getImage(byte [] bytes)  {
            Image image = null;
            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            try {
                image = ImageIO.read(bais);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            return image;
        public BufferedImage getBufferedImage(Image image) {
            int width = image.getWidth(null);
            int height = image.getHeight(null);
            BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = bi.createGraphics();
            g2d.drawImage(image, 0, 0, null);
            return bi;
        }That's it. I hope it is useful.

  • How to disable fading on dragged images while still being able to drag the images themselves?

    When you drag an image, it will be faded out from where your mouse was when you dragged it. I want to be able to see the whole picture, no fade. But I still need to be able to drag the image itself. I've looked at nglayout.enable_drag_images in the config, but it just stops me from being able to drag the image at all.

    I'm sorry, but I don't think there is a way to do this... Most operating systems fade items when they are being dragged, and I don't know if there is a way to counteract that without custom code to handle drag and drop.

  • I'm trying download Firefox Sync. When I open it & tried to drag the icon into my application file, I get a message saying a newer version of Firefox exists & did I want to replace it. Should I replace my Firefox 5 or is there something else I can do?

    I am trying to activate Firefox on my Ipad. I saved the download file. When I opened it and tried to drag the icon into my application file, I got a pop-up message saying that a newer version of Firefox existed and did I want to replace it. Should I replace my Firefox 5 or is there something else I can do?
    I'm afraid I'll lose my browser.

    * Download a new copy of the Firefox program: http://www.mozilla.com/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 [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder], so you won't lose your bookmarks and other personal data.

  • I used to be able to use the reduce picture ( middle button ) using Firefox and dragging the image to another screen. How do I restore this as the reduce button will not work ?

    The top right corner of the screen allows you to reduce the size of your entire image on Firefox . I used to be able to do this so I could drag the image to another screen . Suddenly I cannot do so anymore from my laptop. What can I do ?

    Could you clarify where you are doing your search?
    ''For Firefox's "Search bar",'' which is the box on the right end of the main navigation toolbar with the icon indicating your currently selected search engine, there is a hidden setting for this:
    (1) In a new tab, type or paste '''about:config''' in the address bar and press Enter. Click the button promising to be careful.
    (2) In the search box above the list, type or paste '''sear''' and pause while the list is filtered
    (3) Double-click the '''browser.search.openintab''' preference to switch it from false to true.
    If you test, does it work?
    ''For searches from other places,'' could you be more specific about where you are entering your query (e.g., address bar, built-in home page, on a search engine site)?

  • I just really need to know... After desigining my UX, how do I go about adding the image into ADOBE FLASH BUILDER to script on top of it?

    I just really need to know... After desigining my UX, how do I go about adding the image into ADOBE FLASH BUILDER to script on top of it?
    Any and all advice is welcome.

    Do you have different versions of the graphic novel pages, or is there just one version of the page? If there is one version, can you crop into the page without losing anything important?
    I would guess that there is one version, and that cropping into the page will lose something important. If that's the case, here's how I would handle it:
    Make a stage that is 14:9. The size doesn't matter, but 1400x900 could be a good starting point.
    Put down a background texture that fits well with the look of the other images. Make that fill the 1400x900 stage.
    Place your page graphics so that they are within the center 1200x788 area of the stage.
    Set the stage scalemode to "noBorder".
    You now have a layout that will work on all devices, as narrow as iPad, and as wide as iPhone 5. All without any code. On the widest devices you'll see a bit of your background pattern to the left and right of the page graphic. On the narrowest devices you'll see a bit of background pattern above and below the page graphic. But you won't lose sight of anything important.

  • When using more than one tab, once I have opened a pdf using firefox my laptop will not allow me to type or click in another tab unless I drag the pdf into it's own window?

    when using more than one tab, once I have opened a .pdf using firefox my laptop will not allow me to type or click in another tab unless I drag the .pdf into it's own window? not a major problem just irritating.

    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...

  • Guys, i want to ask on how to resize the images into 1200 pixels wide?

    Guys, i want to ask on how to resize the images into 1200 pixels wide, how to do it? and what are the step by steps on doing that? thank you!!!

    See this link: http://forums.adobe.com/docs/DOC-3691

  • I plugged my usb cable connected with my iphone 4 to the computer, and then it shows up as Iphone, but there is no button to sync, and when i manually drag the files into the storage it would say "Device is no longer responding" and it just would not work

    I plugged my usb cable connected with my iphone 4 to the computer, and then it shows up as Iphone, but there is no button to sync, and when i manually drag the files into the storage it would say "Device is no longer responding" and it just would not work... Please help me and quick

    You need to check out the User Guide here: http://manuals.info.apple.com/en_US/iphone_user_guide.pdf

  • How to change the image into byte and byte array into image

    now i am developing one project. i want change the image into byte array and then byte array into image.

    FileInputStream is = new FileInputStream(file);
    byte[] result = IOUtils.toByteArray(is);
    with apache common IO lib

  • Will the data entered under "Add a description" in iPhoto migrate with the images into Photos?

    Will the data entered under "Add a description" in iPhoto migrate with the images into Photos?

    Thanks for the reply. My particular use of iPhoto is for documents that I have photographed from archives, libraries, and other repositories across the US and Europe. For each one I have added a complete citation and notes. I am so relieved to hear that all my years of work on this will migrate with the new app!

  • When I drag an image into IBA, it rotates 90 degrees.

    I'm having trouble dragging a particular image into iBooks Author.  I took a picture and imported from my camera to iPhoto.  The image had to be rotated 90 degrees, which I did in iPhoto.  I'm using the "Contemporary" template in iBooks Author and I'm trying to drag my image from iPhoto to replace the red, space themed image at the top of a section page.  When I do so, the image reverts to its original instead of the rotated form.  I can't figure out how to rotate the image without rotating the mask.

    Hello Abram1,
    Not sure of the reasons but I would imaging it might have to do with iPhoto and its non destruction approach to editing.
    Have you tried exporting the image out as a new image that would then have the new rotation that you wish applied to it.
    I hope this helps,
    Regards,
    Nigel

Maybe you are looking for

  • How to find the open PR in SAP

    how to find the open PR list in SAP

  • Weblogic 8.1 backward compatible

    Hi all, I created an application using Weblogic8.1 workshop. I want to deploy the same on Weblogic 6.1 but I am getting lot of errors. Is Weblogic 8.1 backward compatible? Thanks in advance. -Jaya

  • Identified faces not merging between iphoto and aperture

    I've been using both iphoto and aperture programs interchangeably to organize my photos and assumed that the work I was doing in one program was updating the other.  Most of the work has been merged between the programs, but I noticed today that the

  • Help with Logic Pro 7 and Yamaha 01X please!

    My friend has purchased an 01X, a 20" G5 iMac with 1.5GB RAM and Logic Pro 7. He is not the 'techiest' of people so was rather hesitant about going this route for his recording purposes. Having used a Yamaha AW4416 to successfully record an album, he

  • User exit needed for KDMAT (customer-material number )

    Hi! I need to find a user exit for filling in the customer-material number (KDMAT) in the Sales order. If there is not a cutomer material info record, the filed should be filled in with the Old material number from the Material master (MARA-BISMT). D