Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6663709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:31:44+00:00 2026-05-26T02:31:44+00:00

I have a custom widget that is actually an image, and i would like

  • 0

I have a custom widget that is actually an image, and i would like to be able to drag it inside an AbsolutePanel and get its coordinates every time. I would like to use the new DND API from GWT 2.4, but i’m having a hard time to implement it. Can someone propose the basic steps i must take?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:31:44+00:00Added an answer on May 26, 2026 at 2:31 am

    The new DnD API introduced with GWT 2.4 doesn’t currently support the AbsolutePanel (see the implementations of the HasAllDragAndDropHandlers interface). Looking at the implementation of FocusPanel it shouldn’t be too hard to enable it for other panels.

    Here’s a quick proof of concept on how to solve your problem:

    public void onModuleLoad() {
        DragImage image = new DragImage();
        image.setUrl(Resources.INSTANCE.someImage().getSafeUri());
        final DropAbsolutePanel target = new DropAbsolutePanel();
        target.getElement().getStyle().setBorderWidth(1.0, Unit.PX);
        target.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
        target.getElement().getStyle().setBorderColor("black");
        target.setSize("200px", "200px");
    
        // show drag over effect
        target.addDragOverHandler(new DragOverHandler() {
    
            @Override
            public void onDragOver(DragOverEvent event) {
                target.getElement().getStyle().setBackgroundColor("#ffa");
            }
        });
    
        // clear drag over effect
        target.addDragLeaveHandler(new DragLeaveHandler() {
    
            @Override
            public void onDragLeave(DragLeaveEvent event) {
                target.getElement().getStyle().clearBackgroundColor();
            }
        });
    
        // enable as drop target
        target.addDropHandler(new DropHandler() {
    
            @Override
            public void onDrop(DropEvent event) {
                event.preventDefault();
                // not sure if the calculation is right, didn't test it really
                int x = (event.getNativeEvent().getClientX() - target.getAbsoluteLeft()) + Window.getScrollLeft();
                int y = (event.getNativeEvent().getClientY() - target.getAbsoluteTop()) + Window.getScrollTop();
                target.getElement().getStyle().clearBackgroundColor();
                Window.alert("x: " + x + ", y:" + y);
                // add image with same URL as the dropped one to absolute panel at given coordinates
                target.add(new Image(event.getData("text")), x, y);
            }
        });
    
        RootPanel.get().add(image);
        RootPanel.get().add(target);
    }
    

    And here the custom panel

    public class DropAbsolutePanel extends AbsolutePanel implements HasDropHandlers, HasDragOverHandlers,
            HasDragLeaveHandlers {
    
        @Override
        public HandlerRegistration addDropHandler(DropHandler handler) {
            return addBitlessDomHandler(handler, DropEvent.getType());
        }
    
        @Override
        public HandlerRegistration addDragOverHandler(DragOverHandler handler) {
            return addBitlessDomHandler(handler, DragOverEvent.getType());
        }
    
        @Override
        public HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler) {
            return addBitlessDomHandler(handler, DragLeaveEvent.getType());
        }
    }
    

    and image class:

    public class DragImage extends Image {
    
        public DragImage() {
            super();
            initDnD();
        }
    
        private void initDnD() {
            // enables dragging if browser supports html5
            getElement().setDraggable(Element.DRAGGABLE_TRUE);
            addDragStartHandler(new DragStartHandler() {
    
                @Override
                public void onDragStart(DragStartEvent event) {
                    // attach image URL to drag data
                    event.setData("text", getUrl());
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have extended View to build a custom widget. I would like to define
I am making a custom widget that I would like to use in multiple
I'm using the tree control in GWT. I have a custom widget that I
I use the following code and I would like to be able to get
I am trying to develop a custom widget for camera preview. I would like
I have a standard jQuery UI dialog. Inside that dialog, I have a custom
If I have a widget that fires a custom event, and that widget is
I'm instantiating a dijit button inside a custom widget. That bit all works fine.
Suppose I have a MyWidget which contains a MySubWidget , e.g. a custom widget
I have developed a custom dijit Templated Widget. I have to do some DOM

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.