在 JTable 上执行拖放操作时,在拖动时会出现所选单元格的轮廓(选择框)。我怎样才能覆盖这种行为而不显示任何东西,但也许是一个特殊的光标?
在 Windows 和 OSX 中运行以下代码显示了我想要覆盖的行为!
import java.awt.BorderLayout;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
public class GestureTest
extends
JFrame
implements
DragGestureListener {
private final DragSource ds;
private final JTable jl;
private static final Object[][] ITEMS = { { "Java" }, { "C" }, { "C++" }, { "Lisp" },
{ "Perl" }, { "Python" } };
public GestureTest() {
super("Gesture Test");
setSize(200, 150);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent we) {
System.exit(0);
}
});
jl = new JTable(ITEMS, new Object[] { "Langs" });
jl.setDragEnabled(true);
jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getContentPane().add(new JScrollPane(jl), BorderLayout.CENTER);
ds = new DragSource();
// final DragGestureRecognizer dgr =
ds.createDefaultDragGestureRecognizer(
jl, DnDConstants.ACTION_MOVE, this);
setVisible(true);
}
@Override
public void dragGestureRecognized(final DragGestureEvent dge) {
System.out.print("dragGestureRecognized");
}
public static void main(final String args[]) {
new GestureTest();
}
}