我正在尝试在我的树 TableView 和界面中的一些矩形之间创建拖放解决方案。 现在,我可以从 treeTableView 中拖动一行,当我将其拖动到矩形上时,矩形的颜色会发生变化。 但现在我想在拖动不再结束时收到通知,以便我可以改回矩形上的颜色。但我看不到有任何 Activity 这样做。
最佳答案
对于拖动目标,您有四个不同的属性:
onDragEnteredProperty
:当拖动手势进入此Node
时调用
onDragOverProperty
:当拖动手势在此Node
内进行时调用
onDragExitedProperty
:当拖动手势退出此Node
时调用
onDragDroppedProperty
:在拖放手势期间在此Node
上释放鼠标按钮时调用
您可以使用此属性来定义目标Node
的行为,例如:
Rectangle rect = new Rectangle();
rect.setOnDragEntered(value -> {
// Set the drag-over color here
});
rect.setOnDragExited(value -> {
// Reset the original color here
});
rect.setOnDragDropped(value -> {
// Reset the original color here
});
关于java - JavaFX 拖放事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39201766/