Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Guides JavaFX touch and gesture handling for pinch-to-zoom, panning, and multi-touch, with explicit transform ownership.
86% 95%+9 ptsof test cases passed
Passed 21 of 22 test cases with the skill, and 19 of 22 without it.
How should a custom JavaFX component that wraps an ImageView to provide scroll-wheel zooming extend standard JavaFX container classes, and how should it attach its gesture listener?
Attaches event handlers using addEventFilter
3 of 3 safety checks passed
Use this skill when the UI needs touch-aware interaction: zoomable viewports, pannable canvases, or multi-touch surfaces. Libraries such as GestureFX and TuioFX are useful once gestures become central to the product.
import javafx.application.ConditionalFeature;
import javafx.application.Platform;
import javafx.scene.image.ImageView;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.StackPane;
public class ZoomPane extends StackPane {
public ZoomPane(ImageView imageView) {
getChildren().add(imageView);
addEventFilter(ScrollEvent.SCROLL, event -> {
if (!event.isControlDown()) {
return;
}
double factor = event.getDeltaY() > 0 ? 1.1 : 0.9;
imageView.setScaleX(imageView.getScaleX() * factor);
imageView.setScaleY(imageView.getScaleY() * factor);
event.consume();
});
if (Platform.isSupported(ConditionalFeature.INPUT_TOUCH)) {
setStyle("-fx-background-color: derive(cornflowerblue, 80%);");
}
}
}
Next to this one in the catalogue, plus more from the same author.