2013-05-29 59 views
3

我有一個Scrollpane巫婆在VBox中包含多個TitledPanes。我只想在垂直方向上滾動。內容的寬度應限制爲ScrollPane的寬度。當寬度大於ScrollPane的寬度時,如何讓TitledPane裁剪標題? TitledPane將其寬度調整爲標題的寬度,與任何最大寬度,適合寬度或類似設置無關。如何限制ScrollPane內容的寬度

的Fabian

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

Example Image

回答

0

您可以滾動窗格的寬度綁定到titledpanes'的寬度。這裏的重要部分是強制titlepane通過將maxWidth和minWidth屬性設置爲相同的值來恰好匹配一個限制值。

限定fx:id s到適當的控制,並將其注入到控制器類後:

@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)爲垂直框的插圖(填充)。
.subtract(10)是用於您的用例的佈局的默認填充(我認爲)。
並且當然將它們累積爲簡寫爲.subtract(20);)。

+0

啊謝謝。嚎叫時間我只是試圖設置最大寬度而不是最小寬度。 (沒想到最小寬度會有影響......) – Fabian