我一直在尝试使 VBox 可滚动,但似乎没有任何效果。任何人都可以帮助我并告诉我我可能做错了什么吗?谢谢大家。
这就是我所拥有的,但我似乎无法让它发挥作用:
@Component
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS, value = "prototype")
public class Scroller {
final ScrollBar sc = new ScrollBar();
DropShadow shadow = new DropShadow();
public Group scrollableGroup(VBox Container) {
Group root = new Group();
root.getChildren().addAll(Container, sc);
shadow.setColor(Color.GREY);
shadow.setOffsetX(2);
shadow.setOffsetY(2);
sc.setLayoutX(500 + sc.getWidth() + 10);
sc.setMin(0);
sc.setOrientation(Orientation.VERTICAL);
sc.setPrefHeight(500);
sc.setMax(500 * 2);
sc.valueProperty().addListener(new ChangeListener<Number>() {
public void changed(ObservableValue<? extends Number> ov,
Number old_val, Number new_val) {
Container.setLayoutY(-new_val.doubleValue());
}
});
return root;
}
}