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 8052629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:35:33+00:00 2026-06-05T07:35:33+00:00

Java Custom Drag and Drop – no callbacks to TransferHandler. I want to implement

  • 0

Java Custom Drag and Drop – no callbacks to TransferHandler.

I want to implement Custom Drag and Drop functionality for a JPanel
subclass. I following the guidelines of the standard DnD Tutorial:

Drag and Drop and Data Transfer

On the surface, things seem pretty strightforward, but when I actually
try it, I get no indication that any DnD behaviour is happening. In
fact, none of the methods in my TransferHandler are called.

So, let’s review what I did…

I made my own Container class which declares itself to extend JPanel:

public class DnDUnitPanel extends JPanel
{
    ...
}

I copied the ListTransferHandler from this Demo:

Drop Demo

renamed the class as DndUnitTransferHandler, trimmed out code that is
referring to JList objects, and installed System.out.println() statments
on each of the 5 methods in there.

I then instantiate two different instances of DnDUnitPanel like this:

DnDUnitPanel topPanel = new DnDUnitPanel(new GridLayout(0, 4, 6, 6), true);
// topPanel.setDragEnabled(true);
topPanel.setName("Top Panel");
topPanel.setTransferHandler(new DnDUnitTransferHandler());

DnDUnitPanel bottomPanel = new DnDUnitPanel(new GridLayout(0, 4, 6, 6), true);
// bottomPanel.setDragEnabled(true);
bottomPanel.setName("Bottom Panel");
bottomPanel.setTransferHandler(new DnDUnitTransferHandler());

(and I also create some JLabel instances and add() them to the panels
(not shown)).

When I try to drag a JLabel from one panel to another, nothing happens.
So I went back and reread this page:

Transfer Handler

in particular, what it says about setDragEnabled():

turns on drag support. (The default is false.) This method is
defined on each component that supports the drag gesture; the link
takes you to the documentation for JList.

JPanel does not have a setDragEnabled() method. So, I asked myself, what
does that really mean: “component that supports the drag gesture”?

I first figured this must mean something that is declared to implement
MouseListener and/or MouseMotionListener. I modified DnDUnitPanel to
declare that it implements both and provided all the methods. Having
done so, I could see that mousePressed(), mouseClicked(),
mouseDragged(), etc. were getting called, but still nothing in the
TransferHandler was getting called, and still no drag cursor indicating
something was dragged or is ready to be dropped.

I then looked at the source for JList itself and decided that
“supports the drag gesture” really just means something that has a
‘dragEnabled’ property with the associated getter and setter.

So, I declared the property and provided the getter and setter on
DnDUnitPanel by just copying code straight from JList itself (thinking
maybe something I don’t fully understand is calling
isDragEnabled() and looking for a true value to initiate DnD behavior.)

Unfortunately, providing those (and uncommenting the calls above to
DnDUnitPanel.setDragEnabled()) also had no effect.

So… the TransferHandler never gets called(). Obviously, something
important is missing here, but I’m not seeing what that might be.

I’m at a dead end for what to try next.

Anybody see what is missing here?

  • 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-06-05T07:35:36+00:00Added an answer on June 5, 2026 at 7:35 am

    Basically you need a data source.

    Look at the other Stackoverflow question, here and here (a good explanation of DnD)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement a custom java barrier. I don't want to use the
I have several android constructs like custom dialog boxes, drag-and-drop implementations, and other standard
Our company builds custom Java EE web solutions. At the moment, we use standard
in java when you want to do custom painting in a panel, you usually
I want to implement a Custom logger which logs all log entries to a
I have a grails app that uses functionality from a set of custom java
I am trying to implement a custom Java widget using GWT.This requires me to
I am trying to implement a custom Java widget using GWT.This requires me to
I'm trying to write custom JFrame and JPanel for my Java application. Currently, I
We're using the Maven exec:java goal to run a custom java application that configures

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.