i want to use zoom and crop in webview in JavaFx using key + for zoom out and - for zoomin and space for crop and F5 for save the crop image in my application im loading image from one webview to another i had try this
final WebView img = new WebView();
final WebEngine Img = img.getEngine();
final DoubleProperty zoomProperty = new SimpleDoubleProperty(200);
img.addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent e) -> {
if (e.getCode() == KeyCode.ADD || e.getCode() == KeyCode.EQUALS || e.getCode() == KeyCode.PLUS) {
System.out.println("YES");
zoomProperty.set(zoomProperty.get() * 1.1);
}
else if(e.getCode()== KeyCode.SUBTRACT||e.getCode() == KeyCode.MINUS ){
System.out.println("YES");
zoomProperty.set(zoomProperty.get() / 1.1);
}
});
vbox.getChildren().addAll(img);
from this im able to detect the key but zoom is not working.First i have to change arrow pointer cursor to double headed arrow and then + key will zoomout and - key will zoomin. please help as i had debug im able to detect the add and subtract key at the time of key pressed but i want to perform zoom but its not working in webview.
i had solve my answer on my own as im just not adding the zoom property to webview.
img.addEventFilter(KeyEvent.KEY_RELEASED, (KeyEvent e) -> {
if (e.getCode() == KeyCode.ADD || e.getCode() == KeyCode.EQUALS || e.getCode() == KeyCode.PLUS) {
System.out.println("YES");
img.setZoom(img.getZoom() * 1.1);
}
else if(e.getCode()== KeyCode.SUBTRACT||e.getCode() == KeyCode.MINUS ){
System.out.println("YES");
img.setZoom(img.getZoom() / 1.1);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.