나는 ImageViews로 채워진 VBox를 가지고 있으며 VBox는 CENTER의 BorderPane 내에 배치되어 있습니다. 이제 ScrollBar를 움직이면 그 값을 얻었고 YBox에 ScrollBar 값만큼의 위치로 VBox를 재배치합니다. 내 코드는 간단하다 :BorderPane 내부에서 VBox를 재배치하는 방법은 무엇입니까?
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("MyScrollbarSample");
ScrollBar scrollBar = new ScrollBar();
scrollBar.setBlockIncrement(10);
scrollBar.setMax(180);
scrollBar.setOrientation(Orientation.VERTICAL);
// scrollBar.setPrefHeight(180);
scrollBar.setValue(90);
final VBox vBox = new VBox(1);
// vBox.setPrefHeight(180);
for (int i = 1; i < 6; i++) {
vBox.getChildren().add(new ImageView(new Image(getClass().getResourceAsStream("fw" + i + ".jpg"))));
}
scrollBar.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
System.out.println("newValue=" + newValue.doubleValue());
// vBox.setLayoutY(-newValue.doubleValue());
vBox.relocate(vBox.getLayoutX(), - newValue.doubleValue());
}
});
BorderPane borderPane = new BorderPane();
borderPane.setCenter(vBox);
borderPane.setRight(scrollBar);
stage.setScene(new Scene(borderPane));
stage.show();
}
불행하게도 어느 setLayoutY도 내가 스크롤 막대를 이동할 때 이동하지 않는 한 VBox에 변경합니다.
감사합니다.