我正在尝试为 JTable 编写自定义的拖放行为,但无法接收MOUSE_DRAGGED
事件。我猜问题是本机 DnD 操作消耗了该事件(如mouseDragged
's javadoc:中"Due to platform-dependent Drag&Drop implementations, MOUSE_DRAGGED events may not be delivered during a native Drag&Drop operation. "
所述),但我正在寻找一种方法来禁用它,或者解决它。
这是一个展示问题的 SSCCE:
public class DragAndDrop {
@SuppressWarnings("serial")
public static void main(String[] args) {
JFrame f = new JFrame();
f.getContentPane().add(
new JTable(
new Object[][] {{1,2,3},{4,5,6}},
new Object[] {"one", "two", "three"})
{{
addMouseListener(new MouseAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
System.out.println("mouseDragged");
}
@Override
public void mousePressed(MouseEvent e) {
System.out.println("mousePressed");
}
@Override
public void mouseReleased(MouseEvent e) {
System.out.println("mouseReleased");
}
});
}}
);
f.setVisible(true);
}
}