scroll - 如何在调整大小时使 flowpane 滚动

标签 scroll javafx-8 scenebuilder flowpane

我想在调整窗口大小以便能够看到所有矩形时自动显示滚动条

调整大小之前:
befor resizing

调整大小后:
after resizing

在底部,矩形消失了,但它们仍然存在。 那么有没有办法将 Flowpane 与 Scrollpane 结合起来?

我正在使用 SceneBuilder,这是 fxml 代码:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.shape.Rectangle?>


<FlowPane alignment="TOP_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="200.0" stroke="BLACK" strokeType="INSIDE" width="200.0" />
      <Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="200.0" stroke="BLACK" strokeType="INSIDE" width="200.0" />
      <Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="200.0" stroke="BLACK" strokeType="INSIDE" width="200.0" />
      <Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="200.0" stroke="BLACK" strokeType="INSIDE" width="200.0" />
      <Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="200.0" stroke="BLACK" strokeType="INSIDE" width="200.0" />
      <Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="200.0" stroke="BLACK" strokeType="INSIDE" width="200.0" />
   </children>
</FlowPane>

最佳答案

是的,有:只需使用 FlowPane 作为 ScrollPane 的内容,并使用 fitToWidth 来制作 ScrollPane code> 根据可用宽度设置内容的宽度...

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.shape.Rectangle?>

<!-- make ScrollPane resize the content width -->
<ScrollPane fitToWidth="true" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1">
   <content>
      <!-- do not put bounds on the FlowPane size -->
      <FlowPane alignment="TOP_CENTER" maxHeight="-Infinity" maxWidth="Infinity" minHeight="-Infinity" prefWidth="600.0">
         <children>
            <Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="200.0" stroke="BLACK" strokeType="INSIDE" width="200.0" />
            <Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="200.0" stroke="BLACK" strokeType="INSIDE" width="200.0" />
            <Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="200.0" stroke="BLACK" strokeType="INSIDE" width="200.0" />
            <Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="200.0" stroke="BLACK" strokeType="INSIDE" width="200.0" />
            <Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="200.0" stroke="BLACK" strokeType="INSIDE" width="200.0" />
            <Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="200.0" stroke="BLACK" strokeType="INSIDE" width="200.0" />
         </children>
      </FlowPane>
   </content>
</ScrollPane>

关于scroll - 如何在调整大小时使 flowpane 滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42462426/

相关文章:

javascript - 如何在不滚动整个页面的情况下自动滚动内联 div?

javascript - 跳转到网页部分时暂时突出显示 html 元素

jQuery - 滚动经过另一个元素后隐藏固定元素

java - 如何打开 PDF 文件

java - 由于 OSX 中的其他线程,Platform.exit() 未结束 Javafx

java - 遇到编译器错误 : Exception in Application start method.(这是简单的 JavaFX 程序)

c# - 在 C# 中同步多行文本框位置

java - 双击行时无法触发 MouseEvent

java - 无法启动 SceneBuilder?

java - 场景生成器不打开带有注释的 FXML 文件