Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's my work-around for the ScrollPane using ScrollBar.</p> <pre><code>public void setStyle() { // In my program, TextField controls were generate at run-time, so the prefer height is calculated based on number of controls int preHeight = 1000; Group root = new Group(); // This anchor pane contains all control. AnchorPane anchorPane = new AnchorPane(); // TODO: Add control into this anchor pane // anchorPane.getChildren().addAll(); final ScrollBar sc = new ScrollBar(); root.getChildren().addAll(anchorPane, sc); // Set default size for scene to 800 x 600 int sceneW = 800; int sceneH = 600; final Scene scene = new Scene(root, sceneW, sceneH); // Setting for the scroll bar sc.setLayoutX(scene.getWidth()- sc.getWidth()/2 - 1); sc.setMin(0); sc.setOrientation(Orientation.VERTICAL); sc.setPrefHeight(sceneH); sc.setMax(preHeight - sceneH); // In case prefer height is smaller than scene height then hide the scroll bar if(preHeight &lt; sceneH) { sc.setVisible(false); } scene.setRoot(root); // Change the scroll bar and the anchor pane when user change scene's width scene.widthProperty().addListener(new ChangeListener&lt;Number&gt;() { @Override public void changed(ObservableValue&lt;? extends Number&gt; arg0, Number arg1, Number arg2) { sc.setLayoutX(arg2.doubleValue()- sc.getWidth()/2 - 1); anchorPane.setPrefWidth(arg2.doubleValue() - sc.getWidth()); } }); // Change the scroll bar and the anchor pane when user change scene's height scene.heightProperty().addListener(new ChangeListener&lt;Number&gt;() { @Override public void changed(ObservableValue&lt;? extends Number&gt; arg0, Number arg1, Number arg2) { sc.setMax(preHeight - arg2.doubleValue()); if(arg2.doubleValue() &gt;= preHeight) { sc.setVisible(false); } else { sc.setVisible(true); } sc.setPrefHeight(arg2.doubleValue()); anchorPane.setPrefHeight(arg2.doubleValue()); } }); // Change the Y position of anchor pane when user scroll the scroll bar sc.valueProperty().addListener(new ChangeListener&lt;Number&gt;() { public void changed(ObservableValue&lt;? extends Number&gt; ov, Number old_val, Number new_val) { anchorPane.setLayoutY(-new_val.doubleValue()); } }); anchorPane.setPrefSize(scene.getWidth() - sc.getWidth(), scene.getHeight()); } </code></pre> <p>There's one issue with this approach, that's if user use tab key to navigate between control in the screen then the Y location of the scroll bar will not change to corresponding position. You may solve this issue by handling focus event for focusable controls in the anchor pane and set Y position for the scroll bar accordingly. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload