Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] About the event.item of DropTargetEvent!

Hi ,all,
I have found s strage behavior of event.item of DragTargetEvent !. I set a DragSource and DragTarget to a Table whose headers are visible. And When I drag one of its item, the DrapTargetEvent.item doesn't point the right item, actually it seems it point down by one item. I think it counts for the visible headers of the table.
below is my code:
import org.eclipse.swt.*; import org.eclipse.swt.dnd.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
/**
* This program illustrates dragging
*/
public class Snippet185 {
 /**
  * Runs the application
  */
 public void run() {
   Display display = new Display();
   Shell shell = new Shell(display);
   createContents(shell);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }
 private void createContents(Shell shell) {
   shell.setLayout(new FillLayout());
Table table = new Table(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
   table.setHeaderVisible(true);
   TableColumn column = new TableColumn(table, SWT.NONE);
   column.setText("column 1");
   // Seed the table
   TableItem item = new TableItem(table, SWT.NONE);
   item.setText(new String[] { "Test 1"});
   item = new TableItem(table, SWT.NONE);
   item.setText(new String[] { "Test 2"});
   item = new TableItem(table, SWT.BORDER);
   item.setText(new String[] { "Test 3 "});
// Seed the table
   column.pack();
   // Create the types
   Transfer[] types = new Transfer[] { TextTransfer.getInstance()};
   // Create the drag source
DragSource source = new DragSource(table, DND.DROP_MOVE | DND.DROP_COPY);
   source.setTransfer(types);
   source.addDragListener(new DragSourceAdapter() {
     public void dragSetData(DragSourceEvent event) {
         event.data = "DD";
     }
   });
   // Create the drop target
   DropTarget target = new DropTarget(table,
     DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
   target.setTransfer(types);
   target.addDropListener(new DropTargetAdapter() {
public void drop(DropTargetEvent event) {
         System.out.println(event.item);
     }
   });
 }
 /**
  * The application entry point
  * @param args the command line arguments
  */
 public static void main(String[] args) {
   new Snippet185().run();
 }
}


Back to the top