Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何限制滚动窗格内容的宽度_Java_Scala_Javafx 2_Scalafx - Fatal编程技术网

Java 如何限制滚动窗格内容的宽度

Java 如何限制滚动窗格内容的宽度,java,scala,javafx-2,scalafx,Java,Scala,Javafx 2,Scalafx,我有一个滚动窗格,在VBox中包含几个标题窗格。我只想在垂直方向滚动。内容的宽度应限制为滚动窗格的宽度。当标题窗格的宽度大于滚动窗格的宽度时,如何让标题窗格剪裁标题?此时,标题窗格会根据标题的宽度调整其宽度,而不受任何maxWidth、Fit to width或类似设置的影响 费边 <?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import java.util.*?> <

我有一个滚动窗格,在VBox中包含几个标题窗格。我只想在垂直方向滚动。内容的宽度应限制为滚动窗格的宽度。当标题窗格的宽度大于滚动窗格的宽度时,如何让标题窗格剪裁标题?此时,标题窗格会根据标题的宽度调整其宽度,而不受任何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>


您可以将滚动窗格的宽度绑定到标题窗格的宽度。这里的重要部分是通过将标题栏的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)
用于VBox的插图(填充)。
第二个
.subtract(10)
用于在您的用例中使用的布局的默认填充(我认为)。

当然,将它们累加为
。简而言之,减去(20)

啊,谢谢。嚎叫时间我只尝试设置最大宽度,而不是最小宽度。(没想到最小宽度会有影响…)