-
Notifications
You must be signed in to change notification settings - Fork 0
/
zoom.txt
51 lines (40 loc) · 1.6 KB
/
zoom.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.ScrollEvent;
import javafx.stage.Stage;
public class ZoomExample extends Application {
private ImageView imageView = new ImageView();
private ScrollPane scrollPane = new ScrollPane();
final DoubleProperty zoomProperty = new SimpleDoubleProperty(200);
@Override
public void start(Stage stage) throws Exception {
zoomProperty.addListener(arg0 -> {
imageView.setFitWidth(zoomProperty.get());
imageView.setFitHeight(zoomProperty.get());
});
scrollPane.addEventFilter(ScrollEvent.ANY, event -> {
if (event.getDeltaY() > 0) {
zoomProperty.set(zoomProperty.get() * 1.1);
} else if (event.getDeltaY() < 0) {
if (zoomProperty.get() != imageView.getX())
zoomProperty.set(zoomProperty.get() / 1.1);
}
});
imageView.setImage(new Image("001-bill.png"));
imageView.preserveRatioProperty().set(true);
scrollPane.setContent(imageView);
stage.setScene(new Scene(scrollPane, 400, 300));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}