我在ScrollPane中有一個FlowPane。在流程窗格中,我放置了四個矩形形狀。 當我調整(降低)窗口滾動窗格中沒有顯示出滾動條,如下圖所示:如何在ScrollPane大小調整時使滾動條顯示? (在JavaFX中)
但它在某些時候出現了,當我減少規模。
下面是我的代碼:
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();
}
}
I)的滾動窗格的財產我應該檢查,以獲得用於顯示滾動條的缺省值? ii)如何修改代碼以在所需點(調整大小時)顯示滾動條?
您正在使用哪個JDK版本? –
我正在使用JDK 1.7 – Angom