-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
fx2.1
-
2.1 b19
In this code example the content of ScrollPane disappears under certain situations.
If I set scrollPane.setVvalue(Double.MAX_VALUE), while the ScrollPane has no vertical scrollbar, strange behavior occurs: The content appears below the scroll pane.
What I actually wanted, is to scroll to the bottom (if there is no scroll bar, nothing should happen).
I seems, it only works after I resized the window vertically.
Run the code. Click scroll. Nothing happens (correct behavior). Enlarge the window vertically. Click scroll again. The content appears beneath the black Rectangle.
import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class TestApp3 extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(final Stage stage) throws Exception {
final VBox root = new VBox();
final ScrollPane scrollPane = new ScrollPane();
final VBox vBox = new VBox();
vBox.setAlignment(Pos.BOTTOM_CENTER);
for (int i = 0; i < 5; i++) {
vBox.getChildren().add(new Label("hallo"));
}
scrollPane.setContent(vBox);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
vBox.minHeightProperty().bind(scrollPane.heightProperty().subtract(2));
vBox.minHeightProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable observable) {
System.out.println(vBox.minHeightProperty().get());
}
});
VBox.setVgrow(scrollPane, Priority.ALWAYS);
Button button = new Button("scroll");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
scrollPane.setVvalue(Double.MAX_VALUE);
}
});
root.setAlignment(Pos.BOTTOM_RIGHT);
root.getChildren().addAll(scrollPane, button, new Rectangle(50, 300));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
If I set scrollPane.setVvalue(Double.MAX_VALUE), while the ScrollPane has no vertical scrollbar, strange behavior occurs: The content appears below the scroll pane.
What I actually wanted, is to scroll to the bottom (if there is no scroll bar, nothing should happen).
I seems, it only works after I resized the window vertically.
Run the code. Click scroll. Nothing happens (correct behavior). Enlarge the window vertically. Click scroll again. The content appears beneath the black Rectangle.
import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class TestApp3 extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(final Stage stage) throws Exception {
final VBox root = new VBox();
final ScrollPane scrollPane = new ScrollPane();
final VBox vBox = new VBox();
vBox.setAlignment(Pos.BOTTOM_CENTER);
for (int i = 0; i < 5; i++) {
vBox.getChildren().add(new Label("hallo"));
}
scrollPane.setContent(vBox);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
vBox.minHeightProperty().bind(scrollPane.heightProperty().subtract(2));
vBox.minHeightProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable observable) {
System.out.println(vBox.minHeightProperty().get());
}
});
VBox.setVgrow(scrollPane, Priority.ALWAYS);
Button button = new Button("scroll");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
scrollPane.setVvalue(Double.MAX_VALUE);
}
});
root.setAlignment(Pos.BOTTOM_RIGHT);
root.getChildren().addAll(scrollPane, button, new Rectangle(50, 300));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}