How to add a scrollbar in JavaFX
•
Java
I'm trying to add a scrollbar to H@R_869_2419 @Yes Scrollbar was added, but I didn't scroll How can I make it work?
public class ScrollableItems {
public void scrollableItems(H@R_869_2419@ content) {
double height = 180;
ScrollBar sc = new ScrollBar();
content.getChildren().add(sc);
sc.setLayoutX(content.getWidth() - sc.getWidth());
sc.setMin(0);
sc.setOrientation(Orientation.VERTICAL);
sc.setPrefHeight(height);
sc.setMax(height * 2);
sc.valueproperty().addListener(new changelistener<Number>() {
public void changed(ObservableValue<? extends Number> ov,Number old_val,Number new_val) {
content.setLayoutY(-new_val.doubleValue());
}
});
}
}
Add children to H@R_869_2419 @Then pass it to the scrollableitems above( H@R_869_2419 @Content) to add a scrollbar
public H@R_869_2419@ mainItemsWrapper() {
H@R_869_2419@ scrollabelWrapper = new H@R_869_2419@();
scrollabelWrapper.setMaxHeight(180);
H@R_869_2419@ entityDetailViewWrapper = new H@R_869_2419@();
entityDetailViewWrapper.getChildren().addAll(.....);
scrollabelWrapper.getChildren().add(entityDetailViewWrapper);
new ScrollableItems().scrollableItems(scrollabelWrapper);
return scrollabelWrapper;
}
Thank you
Solution
I really don't understand why you want to reinvent the wheel You should use scrollpane instead of
This small example shows how to use the scrollpane class to create a scrollable H@R_869_2419 @:
@Override
public void start(Stage primaryStage) {
H@R_869_2419@ h@R_869_2419@ = new H@R_869_2419@();
Button b = new Button("add");
b.setOnAction(ev -> h@R_869_2419@.getChildren().add(new Label("Test")));
ScrollPane scrollPane = new ScrollPane(h@R_869_2419@);
scrollPane.setFitToHeight(true);
BorderPane root = new BorderPane(scrollPane);
root.setPadding(new Insets(15));
root.setTop(b);
Scene scene = new Scene(root,400,400);
primaryStage.setScene(scene);
primaryStage.show();
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
