As I'm making JavaFX application three in three WebView
in my application, I have to perform zoom in and out function while I press + and - key. Code is given below:
StackPane root = new StackPane();
HBox hbox = new HBox(30); // create a HBox to hold 2 vboxes
// create a vbox with a textarea that grows vertically
VBox vbox = new VBox(10);
//Label label1 = new Label("");
final WebView img = new WebView();
final WebEngine Img = img.getEngine();
final DoubleProperty zoomProperty = new SimpleDoubleProperty(200);
img.addEventFilter(KeyEvent.KEY_RELEASED, (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);
}
});
As through this code im able to listen to the key but zoom in and zoom out is not working. Please help as I have to change mouse pointer to double headed arrow then listen to arrow and + and - key for zoom in and out.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…