Ang*_*gom 5 javafx javafx-2 javafx-8
我在ScrollPane中有一个FlowPane.在流动窗格内,我放了四个Rectangle形状.当我调整窗口大小(缩小)时,滚动窗格没有显示滚动条,如下所示:

但是当我减小尺寸时,它会在某些时候出现.
以下是我的代码:
public class FlowPaneInsideScrollPane extends Application{
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
ScrollPane scrollPane = new ScrollPane();
scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(true);
FlowPane flowPane = new FlowPane();
flowPane.setStyle("-fx-background-color: blue");
flowPane.setPadding(new Insets(10, 10, 10, 10));
flowPane.setHgap(10);
flowPane.setVgap(10);
Rectangle rect1 = new Rectangle(100, 100, Color.RED);
Rectangle rect2 = new Rectangle(100, 100, Color.RED);
Rectangle rect3 = new Rectangle(100, 100, Color.RED);
Rectangle rect4 = new Rectangle(100, 100, Color.RED);
flowPane.getChildren().add(rect1);
flowPane.getChildren().add(rect2);
flowPane.getChildren().add(rect3);
flowPane.getChildren().add(rect4);
scrollPane.setContent(flowPane);
primaryStage.setScene(new Scene(scrollPane, 500, 500));
primaryStage.show();
}
}
Run Code Online (Sandbox Code Playgroud)
i)我应该检查scrollPane的哪个属性来获取显示滚动条的默认值?
ii)如何修改代码以便在所需的位置显示滚动条(在调整大小时)?
ScrollBar策略由ScrollPane.setHbarPolicy(...)和ScrollPane.setVbarPolicy(...)确定.
我认为这里的问题是你有scrollPane.setFitToWidth(true)和scrollPane.setFitToHeight(true),这导致ScrollPane试图强制FlowPane与滚动窗格的视口大小相同.尝试注释掉scrollPane.setFitToHeight(true).如果需要,可以将scrollPane的背景颜色设置为流窗格的相同背景颜色.
| 归档时间: |
|
| 查看次数: |
3621 次 |
| 最近记录: |