我有一个Scrollpane女巫在VBox中包含几个TitledPanes。我只想在垂直方向滚动。内容的宽度应限制为ScrollPane的宽度。当宽度大于ScrollPane的宽度时,如何让TitledPane剪辑标题?目前,TitledPane将其宽度调整为标题的宽度,与任何maxWidth,Fit to Width或类似设置无关。
费边
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="454.0" prefWidth="260.0" xmlns:fx="http://javafx.com/fxml">
<children>
<ScrollPane fitToWidth="true" hbarPolicy="AS_NEEDED" hmax="1.0" pannable="false" prefHeight="200.0" prefViewportWidth="100.0" prefWidth="200.0" vbarPolicy="AS_NEEDED" AnchorPane.bottomAnchor="0.0" AnchorPane. leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<VBox maxWidth="200.0" prefHeight="500.0" prefWidth="480.0" spacing="5.0">
<children>
<TitledPane animated="false" maxWidth="200.0" text="Very long title, should be clipped. Very long title, should be clipped. " textOverrun="CLIP" wrapText="true">
<content>
<AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="500.0" prefWidth="200.0">
<children>
<ListView prefHeight="500.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</content>
</TitledPane>
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</VBox>
</content>
</ScrollPane>
</children>
</AnchorPane>
答案 0 :(得分:0)
您可以将滚动窗格的宽度绑定到标题窗格的宽度。这里的重要部分是通过将其maxWidth和minWidth属性设置为相同的值来强制titlepane恰好适合一个限制值。
将fx:id
定义为适当的控件并将它们注入控制器类后:
@FXML
private ScrollPane demoScrollPane;
@FXML
private TitledPane demoTitledPane;
...
// in initialize
demoTitledPane.maxWidthProperty().bind(demoScrollPane.widthProperty().subtract(10).subtract(10));
demoTitledPane.minWidthProperty().bind(demoScrollPane.widthProperty().subtract(10).subtract(10));
首先.subtract(10)
用于VBox的插图(填充)
第二个.subtract(10)
用于在您的用例中使用的布局的默认填充(我认为)
当然,总之将它们累积为.subtract(20)
;)。