0
public void dropAccept(final DropTargetEvent event)
{
if (TextTransfer.getInstance().isSupportedType(event.currentDataType))
{
final String d=(String)TextTransfer.getInstance().nativeToJava(event.CurrentDataType);
GC gc = new(text);
//text is the name assigned to the Canvas
text.addPaintListener(new PaintListener()
 {
 public void paintControl(PaintEvent e)
 {
  int x= event.x- shell.getBounds().x - text.getBounds().x;
  int y=event.y - shell.getBounds().y - text.getBounds().y;
  e.gc.drawString(d, x, y);
  }
  }); } }

This code snippet is part of a larger class that implements drag drop of text onto a canvas. The problem is that, the actual dropping of text is not seen on the canvas after I drop it but only after I minimize the shell and then maximize it again. Can anyone please tell me how I can make drop actions immediately visible by modifying this code?

Loktar
  • 34,764
  • 7
  • 90
  • 104
Asher
  • 811
  • 3
  • 10
  • 19

1 Answers1

0

You have not done anything to cause the control to be redrawn. Call

text.redraw();

to request that the control is redrawn (by calling the paint listener).

Note: If you add paint listeners on every drop you are going to end up with lots of listeners registered.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • But I've used drawstring to set the text on the canvas? – Asher Jul 09 '14 at 19:29
  • Your drawString is in a paint listener, this listener will not be called until the control needs to be redrawn and you have not done anything to tell SWT that the control needs to be redrawn. – greg-449 Jul 09 '14 at 19:42