highlighting the target of a tree drag?

T

timasmith

Precondition: I do *not* want to extend JTree...

I do have the dnd dragging action working with the code below.

I now want to have the target light up - adding minimal code of course.

thanks!

MyDragDropListener ddl = new MyDragDropListener(reqTree) {
public boolean dropTarget(DefaultMutableTreeNode newparent,
DefaultMutableTreeNode nodeDragged) {
.....
}
};

myTree.setDragEnabled(true);
DropTarget dt = new DropTarget(myTree, ddl);
myTree.setDropTarget(dt);
 
B

Bart Cremers

You probably can get there with adding a mousemotionlistener to the
tree and then changing the background of the TreeCellRenderer of the
node under the mouse cursor. It's probably better to write your own
renderer (examples enough on the net) and install that one instead of
working on the default TreeCellRenderers installed on the tree.

Regards,

Bart
 
R

Raymond DeCampo

Precondition: I do *not* want to extend JTree...

I do have the dnd dragging action working with the code below.

I now want to have the target light up - adding minimal code of course.

thanks!

MyDragDropListener ddl = new MyDragDropListener(reqTree) {
public boolean dropTarget(DefaultMutableTreeNode newparent,
DefaultMutableTreeNode nodeDragged) {
.....
}
};

myTree.setDragEnabled(true);
DropTarget dt = new DropTarget(myTree, ddl);
myTree.setDropTarget(dt);

Try using JTree.setTransferHandler() instead. I haven't tried it with a
JTree, but it works as you desire on JTables.

HTH,
Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top