[英]JavaFX GridPane inside ScrollPane inside GridPane can't set ScrollPane Growing
大家好 !
我有一個簡單的問題:我正在使用FXML文件,並且已經完成以下布局:
我正在嘗試擴大列1(行跨度3)內的Scrollpane的高度
使用此層次結構:(突出顯示了頂部GridPane控制器-它位於VBox內)
與目標ScrollPane更加接近:
我的問題是我正在向ScrollPane內部的GridPane中動態添加行(在另一個GridPane容器內部); 並且我不能添加超過3列(顯然是Vbox容器的大小),但是如果我移除滾動窗格,我可以添加我不希望的任何行,但是由於Vbox / GridPane范圍之外的行消失了。 ..
是否可以做我不想做的事情(多行GridPane行中的ScrollPane中的GridPane)? 我以為它會“開箱即用”,但似乎真的不是:-(
這是因為ScrollPane Max / Min(我使用所有大小的容器和/或頂部容器-Vbox和ScrollPane-都沒有成功...)還是因為GridPane父級設置了最大高度並阻止了ScrollPane高度增長?
我已經嘗試過此解決方案: 如何滾動以使ScrollPane內容內的Node可見? 沒有成功:-(
有任何想法嗎 ? 對於所有!
在“是否有可能做我想做的事情(GridPane內的ScrollPane內的GridPane)”這一問題的中間回答這個問題! 這是它的fxml代碼(不要介意常量,我只是在場景生成器中將其放在一起):
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children><ScrollPane prefHeight="200.0" prefWidth="200.0">
<content><GridPane prefHeight="132.0" prefWidth="297.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</content></ScrollPane>
</children>
</GridPane>
做到這一點的訣竅是,使滾動條具有額外的行/列,而又不使所有現有行變小,這是每次動態添加一行時都要調整最里面的網格的高度,這將確保網格的尺寸超出尺寸滾動窗格,因此使滾動窗格“滾動”
例如(偽代碼):
onButtonPress{
resizeGridPane(sizeOfRow+paddingBetweenRows);
AddRowInDesiredLocation(location);
}
我認為這將為您帶來理想的效果。
編輯
在注意到位於網格窗格內的滾動窗格內的vbox之后,您必須適當調整vbox和網格窗格的大小,以查看滾動窗格的“滾動”效果,如果您僅調整網格窗格的大小,您將簡單地得到越來越小的行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.