我有以下 JavaFX FXML 结构:
<BorderPane fx:id="mainWindow" prefHeight="500.0" prefWidth="800.0" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml/1">
<stylesheets>
<URL value="@mainwindow.css"/>
</stylesheets>
<top>
<fx:include fx:id="buttonPanel" source="/com/example/app/chart/buttons/buttonPanel.fxml" />
</top>
<center>
<BorderPane fx:id="chartContainer">
<center>
<fx:include fx:id="chartPanel" source="/com/example/app/chart/chartpanel/chartPanel.fxml" />
</center>
<right>
<fx:include fx:id="rightAxisPanel" source="/com/example/app/chart/rightaxis/rightAxisPanel.fxml" />
</right>
</BorderPane>
</center>
</BorderPane>
作为chartPanel
和rightAxisPanel
:
<AnchorPane fx:id="chartPanel" styleClass="chartPanelClass" xmlns:fx="http://javafx.com/fxml/1">
<stylesheets>
<URL value="@chartpanel.css"/>
</stylesheets>
</AnchorPane>
和
<AnchorPane fx:id="rightAxisPanel" prefWidth="100.0" minWidth="100.0" styleClass="rightAxisPanelClass" xmlns:fx="http://javafx.com/fxml/1">
<stylesheets>
<URL value="@rightaxispanel.css"/>
</stylesheets>
</AnchorPane>
这会生成下图:
到目前为止,一切顺利。
但是如果我减小窗口的大小,右侧面板就会被截断 - 看看与 rigthAxisPanel 相对应的黄色区域是如何被截断的 -。
如何才能使中央面板被截断?
最佳答案
中心 AnchorPane
的最小宽度可防止其缩小。将值设置为 0 以确保允许缩小。
此外,您应该将 clip
应用于 AnchorPane
以避免其内容显示在其右边界的右侧。如果您在右侧使用(半)透明背景,更改 viewOrder
或者将右侧节点放在外部 BorderPane
中,则可能会发生这种情况。
<AnchorPane fx:id="chartPanel" styleClass="chartPanelClass" xmlns:fx="http://javafx.com/fxml/1" minWidth="0">
<stylesheets>
<URL value="@chartpanel.css"/>
</stylesheets>
<clip>
<Rectangle width="${chartPanel.width}" height="${chartPanel.height}"/>
</clip>
</AnchorPane>
关于JavaFX - BorderPane,确保右 Pane 始终获得最小宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56872592/