You may not need to use DragBoard at all, instead just save the dragged item in to member var then receive it from there. Following code works well, just don't use dragBoard.startDragAndDrop() function with that TransferMode. Instead code that functionality, that is how i prevent the Java DragBoard to set that ugly System-Cursor! I know if you drag data (String,Html,File) from the OS-System over the scene it will use the nicier OS drag cursor labels with some system texts like "copy file" or "link" but if you just need to drag some internal java objects the use of that DragBoard isn't neccesary, it would show these ugly empty cursor labels anyway. The method setOnDragOver() doesn't responds if dragBoard.startDragAndDrop() wasn't called before, but instead you can take use of the "start full drag" method row.startFullDrag(), then the setOnMouseDragXX() (XX:Entered,Exited,Released) methods are available to use. Beside, the DragBoard class is final, there is no way to overwrite the responsible method implementations. Here is some example code that works in my case i use it to sort table rows manually, just recode it and adapt it to your needs:
private ToggleTableRowCell<AbstractNodeItem> selRow = null;
private ToggleTableRowCell<AbstractNodeItem> styledRow = null;
private ToggleTableRowCell<AbstractNodeItem> dropRow = null;
private static final String DROP_DOWN_TABLEROW_HINT_STYLE = "-fx-border-width:1; -fx-border-color: transparent color-cell-border color-dragged color-cell-border;";
private static final String DROP_UP_TABLEROW_HINT_STYLE = "-fx-border-width:1; -fx-border-color: color-dragged color-cell-border color-cell-border color-cell-border;";
private static final String DROP_FORBIDDEN_TABLEROW_HINT_STYLE = "-fx-border-width:1; -fx-border-color: red;";
Image cursorForbidden = new Image("/resources/images/YourCursor.png");
// make own cursor
Cursor forbiddenCursor = new ImageCursor(cursorForbidden, cursorForbidden.getWidth() / 2,
cursorForbidden.getHeight() / 2);
ImageView rowSnapshot = new ImageView();
/* TableRowFactory with Drag & Drop Sorting */
tableView.setRowFactory(table -> {
ToggleTableRowCell<AbstractNodeItem> row = new ToggleTableRowCell<>();
/* adding manual sorting functionality */
row.setOnDragDetected(event -> {
if (row.isEmpty()) { return; }
this.selRow = row;
Integer itemIndex = row.getItem().getID();
// Get snapshot of the row
SnapshotParameters snapshotParams = new SnapshotParameters();
snapshotParams.setFill(Color.TRANSPARENT);
WritableImage snapshot = row.snapshot(snapshotParams, null);
rowSnapshot.setImage(snapshot);
// Start full drag
row.startFullDrag();
ClipboardContent cc = new ClipboardContent();
cc.put(SERIALIZED_MIME_TYPE, itemIndex);
final String data = row.getItem().getData();
cc.putString(data);
event.consume();
});
row.setOnMouseDragEntered(event -> {
if (SortOrder.ID.isNotCurrent()) { return; }
// remove old CSS-Hint
if (null != this.styledRow) {
this.styledRow.setStyle("");
}
if (!row.isEmpty() && row != this.selRow) {
this.dropRow = row;
}
this.styledRow = row;
int selRowIndex = this.selRow.getIndex();
// can't drop on itself
if (row.getIndex() == selRowIndex) {
this.styledRow.setStyle(DROP_FORBIDDEN_TABLEROW_HINT_STYLE);
tableView.setCursor(forbiddenCursor);
} else {
if (row.isEmpty()) {
if (selRowIndex == tableView.getItems().size() - 1) {
this.styledRow = this.selRow;
this.styledRow.setStyle(DROP_FORBIDDEN_TABLEROW_HINT_STYLE);
this.dropRow = null;
tableView.setCursor(forbiddenCursor);
} else {
this.styledRow = this.dropRow;
this.styledRow.setStyle(DROP_DOWN_TABLEROW_HINT_STYLE);
tableView.setCursor(Cursor.HAND);
}
} else {
if (selRowIndex > row.getIndex())
this.styledRow.setStyle(DROP_UP_TABLEROW_HINT_STYLE);
else {
this.styledRow.setStyle(DROP_DOWN_TABLEROW_HINT_STYLE);
}
tableView.setCursor(Cursor.HAND);
}
}
});
return row;
});
tableView.setOnMouseDragExited(e -> {
if (null != styledRow) {
styledRow.setStyle("");
}
tableView.setCursor(Cursor.DEFAULT);
});
tableView.setOnMouseDragReleased(event -> {
// remove old CSS-Hint
if (null != styledRow) {
styledRow.setStyle("");
}
tableView.setCursor(Cursor.DEFAULT);
if (!SortOrder.ID.isCurrent()) { return; }
/* clear CSS-Hint-Style */
if (null != styledRow) {
styledRow.setStyle("");
}
if (null == dropRow) { return; }
int dropIndex = dropRow.getIndex();
int selRowIndex = selRow.getIndex();
// don't drop on itself or empty cells
if (dropRow.getIndex() != selRowIndex) {
// cut and move the cell here
}
});