Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+21 votes

Is there is a way to add a new VBox inside a ScrollPane in such a way that the VBox will be positioned right under the already existing content of the ScrollPane. Essentially, I want to add content to a ScrollPane and ensure that the new VBox is displayed below the existing content within the scrolling area.

asked in CSC305 Fall 2023 by (1 point)

1 Answer

+7 votes

The key is to ensure that the ScrollPane's content is a layout container (like another VBox) that can hold multiple children. Here's how you can do it:
1. Create primary Layout Container (scrollpane) and set content to VBox.
ScrollPane scrollPane = new ScrollPane();
VBox mainContent = new VBox();
scrollPane.setContent(mainContent);

  1. Add exisiting content to the VBox
    mainContent.getChildren().add(existingContent1);

  2. Adjust ScrollPane properties:
    scrollPane.setFitToWidth(true);

answered by (1 point)
...