1 package org
.eclipse
.tracecompass
.internal
.provisional
.tmf
.ui
.views
.timegraph2
.swtjfx
.examples
;
3 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
5 import javafx
.application
.Application
;
6 import javafx
.beans
.value
.ChangeListener
;
7 import javafx
.beans
.value
.ObservableValue
;
8 import javafx
.scene
.Node
;
9 import javafx
.scene
.Scene
;
10 import javafx
.scene
.control
.ScrollPane
;
11 import javafx
.scene
.paint
.Color
;
12 import javafx
.scene
.shape
.Rectangle
;
13 import javafx
.stage
.Stage
;
16 public class Example
extends Application
{
18 public void start(Stage stage
) {
19 Node content
= new Rectangle(1000, 700, Color
.GREEN
);
20 ScrollPane scrollPane
= new ScrollPane(content
);
21 scrollPane
.setPrefSize(500, 300);
23 ChangeListener
<Object
> changeListener
= new ChangeListener
<Object
>() {
25 public void changed(ObservableValue
<?
extends Object
> observable
, Object oldValue
, Object newValue
) {
26 double hmin
= scrollPane
.getHmin();
27 double hmax
= scrollPane
.getHmax();
28 double hvalue
= scrollPane
.getHvalue();
29 double contentWidth
= content
.getLayoutBounds().getWidth();
30 double viewportWidth
= scrollPane
.getViewportBounds().getWidth();
33 Math
.max(0, contentWidth
- viewportWidth
) * (hvalue
- hmin
) / (hmax
- hmin
);
35 double vmin
= scrollPane
.getVmin();
36 double vmax
= scrollPane
.getVmax();
37 double vvalue
= scrollPane
.getVvalue();
38 double contentHeight
= content
.getLayoutBounds().getHeight();
39 double viewportHeight
= scrollPane
.getViewportBounds().getHeight();
42 Math
.max(0, contentHeight
- viewportHeight
) * (vvalue
- vmin
) / (vmax
- vmin
);
44 System
.out
.printf("Offset: [%.1f, %.1f] width: %.1f height: %.1f %n",
45 hoffset
, voffset
, viewportWidth
, viewportHeight
);
48 scrollPane
.viewportBoundsProperty().addListener(changeListener
);
49 scrollPane
.hvalueProperty().addListener(changeListener
);
50 scrollPane
.vvalueProperty().addListener(changeListener
);
52 Scene scene
= new Scene(scrollPane
, 640, 480);
53 stage
.setScene(scene
);
58 public static void main(String
[] args
) {
This page took 0.033423 seconds and 5 git commands to generate.