DefaultTableModel modeltable = new DefaultTableModel(8,8);
table = new JTable(modeltable);
table.setBorder(BorderFactory.createLineBorder (Color.blue, 2));
int height = table.getRowHeight();
table.setRowHeight(height=50);
table.setColumnSelectionAllowed(true);
table.setDragEnabled(true);
le1.setFillsViewportHeight(true);
panel.add(table);
panel.setSize(400,400);
DnDListener dndListener = new DnDListener();
DragSource dragSource = new DragSource();
DropTarget dropTarget1 = new DropTarget(table, dndListener);
DragGestureRecognizer dragRecognizer2 = dragSource.
createDefaultDragGestureRecognizer(option1,
DnDConstants.ACTION_COPY, dndListener);
DragGestureRecognizer dragRecognizer3 = dragSource.
createDefaultDragGestureRecognizer(option2,
DnDConstants.ACTION_COPY, dndListener);
}
}
我在将鼠标侦听器添加到作为放置目标的“表”时遇到问题,无论它从鼠标中落下的任何地方都接受放置组件。在此代码中,当组件放入放置目标时,它始终会转到默认位置。我无法自定义放置目标的位置。请有人帮我解决这个问题。提前致谢