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