4

VBoxにいくつかのTitledPanesを含むScrollpaneウィッチがあります。縦方向にのみスクロールしたい。コンテンツの幅は、ScrollPane の幅に制限する必要があります。TitledPane の幅が 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>

サンプル画像

4

1 に答える 1

0

スクロールペインの幅をタイトル付きペインの幅にバインドできます。ここで重要なのは、maxWidth プロパティと minWidth プロパティの両方を同じ値に設定して、タイトルペインを 1 つの制限値に合わせることです。

s を適切なコントロールに定義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));

1.subtract(10)つ目は、VBox のインセット (パディング) です。
2 つ目.subtract(10)は、ユースケースで使用されているレイアウトのデフォルトのパディング (と思います) です。
そしてもちろん .subtract(20)、要するにそれらを蓄積します;)。

于 2013-06-09T23:24:09.310 に答える