我的GameBoard所需要的GridPane(应该容纳模拟器地形所具有的“平铺”量)无法正确地容纳在ScrollPane中。
转移层次结构并使用彩色容器来识别问题,这无助于解决问题本身。
包含GameBoard的主容器FXML
<SplitPane dividerPositions="0.5" BorderPane.alignment="CENTER">
<items>
<AnchorPane>
<children>
<TextArea layoutX="1.0" layoutY="-14.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
<ScrollPane prefWidth="800" prefHeight="500" hbarPolicy="ALWAYS" vbarPolicy="ALWAYS" >
<GameBoardCC fx:id="gameBoard" >
</ScrollPane>
</items>
</SplitPane>
自定义控件本身:
<fx:root xmlns:fx="http://javafx.com/fxml/1" type="AnchorPane" xmlns="http://javafx.com/javafx/8.0.221">
<GridPane fx:id="gameBoard"
style="-fx-background-color: green">
</GridPane>
</fx:root>
基本上是添加这些项目的代码,我敢肯定我从Stackoverflow那里获得了大部分
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
// create node
TerrainNode node = new TerrainNode ("Item " + i + "/" + j,i * 100,j *100,100,100);
node.setOpacity (0.5);
// add node to group
gameBoard.getchildren ( ).add (node);
}
}
Slider行为的图片,由于某种原因,这些节点没有添加到Gridpane中,而是添加到了Gridpane中?
Pictures of the Slider Situation
我希望将滑块“卡住”在50%的位置(尽管这不是我现在主要关注的问题),并且由于我的模拟应该具有可变的网格大小以及固定的瓦片大小,因此滚动条应该出现在例如20x20的网格上,或者将来客户端太小时出现。