Get ScrollPane size when set by anchor - JavaFX

3

I have a ScrollPane anchored on the 4 sides of an AnchorPane so that when I resize the screen, the scroll also resizes. So I do not need to specify a fixed size. That's how it works.

The problem is that in this way the methods getPrefWidth() , getWidth() , getMinWidth() , getMaxWidth() do not return me the current scroll size.

Does anyone know how to get the size of the ScrollPane by defining its size by the anchor and not by the% size definition?     

asked by anonymous 20.07.2018 / 03:14

2 answers

2

You can use the getBoundsInParent function or getBoundsInLocal . These are functions that calculate the node dimensions based on their coordinates. Then use the getHeight () and getWidth () methods (or others you deem appropriate).

Example:

AnchorPane parent = new AnchorPane();
ScrollPane child = new ScrollPane();

AnchorPane.setTopAnchor(child, 10.0);
AnchorPane.setBottomAnchor(child, 10.0);
AnchorPane.setLeftAnchor(child, 10.0);
AnchorPane.setRightAnchor(child, 10.0);

parent.getChildren().add(child);

// Painel principal
Scene scene = new Scene(parent, 200, 200); 
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();

System.out.println("Height: " + child.getBoundsInParent().getHeight()); // 180
System.out.println("Width: " + child.getBoundsInParent().getWidth()); //180

References: Get the Dimension of a Node

    
22.07.2018 / 17:12
0

For the vertical bar:

jScrollPane1.getVerticalScrollBar().getMaximum()

or to the horizontal bar:

jScrollPane1.getHorizontalScrollBar().getMaximum()
    
20.07.2018 / 20:45