Код: Выделить всё
public class CursorTest extends Application {
@Override
public void start(Stage primaryStage) {
VBox dndBox = new VBox(new Label("DragAndDrop"));
dndBox.setPrefSize(100, 100);
dndBox.setStyle("-fx-background-color: yellow");
dndBox.setOnDragDetected(event -> {
Dragboard db = dndBox.startDragAndDrop(TransferMode.COPY);
ClipboardContent content = new ClipboardContent();
content.putString("test");
db.setContent(content);
event.consume();
});
VBox handBox = createColoredBox(Color.LIGHTBLUE, Cursor.HAND);
VBox closedHandBox = createColoredBox(Color.LIGHTCORAL, Cursor.CLOSED_HAND);
VBox openHandBox = createColoredBox(Color.LIGHTGREEN, Cursor.OPEN_HAND);
VBox root = new VBox(10, dndBox, handBox, closedHandBox, openHandBox);
Scene scene = new Scene(root, 320, 350);
primaryStage.setTitle("Cursor Test");
primaryStage.setScene(scene);
primaryStage.show();
}
private VBox createColoredBox(Color color, Cursor cursor) {
VBox box = new VBox(new Label(cursor.toString()));
box.setPrefSize(100, 100);
box.setStyle(String.format("-fx-background-color: #%s;", color.toString().substring(2, 8)));
box.setCursor(cursor);
return box;
}
public static void main(String[] args) {
launch(args);
}
}
, как вы можете видеть, когда я выполняю Drag и Drop, Cursor изменяется в закрытую руку. Однако, когда я перемещаю мышь на три остальных Vbox, курсор остается прежним. Может ли кто-нибудь сказать мне, как сделать курсор закрытой рукой при падении над Vbox без перетаскивания?>
Подробнее здесь: https://stackoverflow.com/questions/796 ... -in-javafx