繁体   English   中英

JavaFX-BorderPane,确保右窗格始终具有最小宽度

[英]JavaFX - BorderPane, ensuring that Right Pane gets always a minimum width

我具有以下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>

正在chartPanelrightAxisPanel

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM