• Post Reply Bookmark Topic Watch Topic
  • New Topic

Add greyish/ghosted drag images to the tree

 
Hetal Seth
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I am looking to add greyish/ghosted drag images to the tree. What I mean is, when u drag & drop a folder in windows, the object becomes greyish/ghosted. I am trying to implement the same functionality in my project, but unsuccessful.
Any clues ?
Thanks,
Hetal Seth
[ July 11, 2002: Message edited by: Hetal Seth ]
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to use your own TreeCellRenderer. the renderer would have to react on dragging events and change the node value (icon and text) appropriately.
c
 
Hetal Seth
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for ur reply, but that is what I was tryin to do. The code below is used in the dragGestureRecognized() method:
JTree tree = (JTree)event.getComponent();
Point point = event.getDragOrigin();
//TreePath path = tree.getPathForLocation(toInt(point.getX()), toInt(point.getY()));
TreePath path = tree.getLeadSelectionPath();
Rectangle recPath = tree.getPathBounds(path);
Point pt = new Point();
pt.setLocation(toInt(point.getX())- toInt (recPath.getY()), toInt(point.getY())- toInt(recPath.getY()) );
System.out.println("dragGestureRecognized() ******************** 1");
// Get the tree cell renderer
JLabel jLabel = (JLabel) tree.getCellRenderer().getTreeCellRendererComponent
(
tree,
path.getLastPathComponent(),
false,
tree.isExpanded(path),
tree.getModel().isLeaf (path.getLastPathComponent()),
0,
false
);
jLabel.setSize((int)recPath.getWidth(), (int)recPath.getHeight());
System.out.println("dragGestureRecognized() ******************** 2");
// Get the ghostly image
BufferedImage bufImage = new BufferedImage
(
(int)recPath.getWidth(), (int)recPath.getHeight(),
BufferedImage.TYPE_INT_ARGB_PRE);
System.out.println("dragGestureRecognized() ******************** 3");
Graphics2D g2 = bufImage.createGraphics();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f));
jLabel.paint(g2);
System.out.println("dragGestureRecognized() ******************** 4");
//event.startDrag(DragSource.DefaultCopyDrop, new TransferWrap(path), this);

Appreciate ur input.
Thanks,
Hetal Seth
 
Hetal Seth
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Does it have to do anything with the DataFlavors ?
This things drivin me crazzy ....
Thanks,
Hetal
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hu, I never call getTreeCellRendererComponent(). that is done by the tree. I rather write my own TreeCellRenderer:

whenever the image should switch to greyish you must assure that the method getTreeCellRendererComponent gets called, that means that the cells are rendered again. this is the case when the JTree gets revalidated for example. through the object value you should be able to determine which object is currently dragged (add some method of kind isDragged() to your subtype of TreeNode).
hope that helps!
chantal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!