当前位置: 首页 > 知识库问答 >
问题:

为什么我的javafx scrollpane会立即滚动到底部?

景国兴
2023-03-14

我有一个无法调整大小的设置面板,它变得越来越拥挤,所以我决定将包含设置的gridpane添加到滚动窗格中。问题是当应用程序启动时,滚动窗格从底部开始。奇怪的是,我将HValue设置为0,它应该从顶部开始。这是在场景生成器中显示的gif:https://gyazo.com/f10a1641b8357e4fc30cd180c0425dae没有任何代码与scrollpane交互,正如您所看到的,scene builder预览窗口也有相同的问题,因此它与FXML有关。要复制它,您只需使用下面共享的fxml自己设置一个javafx项目,然后运行它,看看滚动条是如何跳到底部的。完整的FXML文件:https://pastebin.com/aS3Dn3pH.仅滚动窗格内容的片段:

 <AnchorPane fx:id="settingsPane" layoutY="86.0" prefHeight="381.0" prefWidth="380.0">
    <ImageView layoutX="84.0" layoutY="-28.0" pickOnBounds="true" preserveRatio="true">
        <Image url="@images/up.png" />
    </ImageView>
  <ScrollPane fx:id="settingsScrollPane" hbarPolicy="NEVER" pickOnBounds="false" prefWidth="480.0" stylesheets="@style.css" vvalue="1.0" AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="0.0">
     <content>
          <GridPane hgap="10.0" maxHeight="-Infinity" prefWidth="480.0">
              <columnConstraints>
                  <ColumnConstraints halignment="LEFT" hgrow="SOMETIMES" minWidth="10.0" prefWidth="270.0" />
                  <ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES" minWidth="10.0" prefWidth="270.0" />
              </columnConstraints>
              <rowConstraints>
                  <RowConstraints maxHeight="-Infinity" minHeight="35.0" prefHeight="30.0" />
                  <RowConstraints maxHeight="-Infinity" minHeight="35.0" prefHeight="30.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="-Infinity" minHeight="35.0" prefHeight="30.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="-Infinity" minHeight="35.0" prefHeight="30.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="-Infinity" minHeight="35.0" prefHeight="30.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="-Infinity" minHeight="35.0" prefHeight="30.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="-Infinity" minHeight="35.0" prefHeight="30.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="-Infinity" minHeight="35.0" prefHeight="30.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="-Infinity" minHeight="35.0" prefHeight="30.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="-Infinity" minHeight="35.0" prefHeight="30.0" vgrow="SOMETIMES" />
              <RowConstraints maxHeight="-Infinity" minHeight="35.0" prefHeight="30.0" vgrow="SOMETIMES" />
              <RowConstraints maxHeight="-Infinity" minHeight="35.0" prefHeight="30.0" vgrow="SOMETIMES" />
              </rowConstraints>
              <padding>
                  <Insets bottom="20.0" left="30.0" right="30.0" top="20.0" />
              </padding>
              <Label text="%no_away" textFill="WHITE" GridPane.valignment="BOTTOM">
                  <font>
                      <Font size="16.0" />
                  </font>
              </Label>
              <Label alignment="TOP_LEFT" text="%no_away_message" textFill="#f2efef" wrapText="true" GridPane.rowIndex="1" GridPane.valignment="TOP">
                  <font>
                      <Font size="13.0" />
                  </font>
              </Label>
              <Label text="%auto_queue" textFill="WHITE" GridPane.rowIndex="2" GridPane.valignment="BOTTOM">
                  <font>
                      <Font size="16.0" />
                  </font>
              </Label>
              <Label text="%auto_queue_message" textFill="#f2efef" wrapText="true" GridPane.rowIndex="3" GridPane.valignment="TOP">
                  <font>
                      <Font size="13.0" />
                  </font>
              </Label>
              <Label text="%quick_replies" textFill="WHITE" GridPane.rowIndex="4" GridPane.valignment="BOTTOM">
                  <font>
                      <Font size="16.0" />
                  </font>
              </Label>
              <Label text="%quick_replies_message" textFill="#f2efef" wrapText="true" GridPane.rowIndex="5" GridPane.valignment="TOP">
                  <font>
                      <Font size="13.0" />
                  </font>
              </Label>
              <Separator opacity="0.33" prefHeight="1.0" prefWidth="307.0" GridPane.columnSpan="2" GridPane.rowIndex="10" />
              <JFXButton fx:id="craftKeyBtn" maxWidth="1.7976931348623157E308" onAction="#handleSettingsButtonPressed" prefHeight="31.0" prefWidth="180.0" style="-fx-background-color: #1e2328; -fx-border-color: d9ae50;" text="%craft_all_keys" textFill="#d9ae50" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.rowIndex="11" GridPane.valignment="CENTER">
                  <font>
                      <Font name="System Bold" size="11.0" />
                  </font>
              </JFXButton>
              <JFXButton fx:id="disenchantBtn" maxWidth="1.7976931348623157E308" onAction="#handleSettingsButtonPressed" prefHeight="31.0" prefWidth="180.0" ripplerFill="#1986b1" style="-fx-background-color: #1e2328; -fx-border-color: d9ae50;" text="%disenchant_champions" textFill="#d9ae50" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="11" GridPane.valignment="CENTER">
                  <font>
                      <Font name="System Bold" size="11.0" />
                  </font>
              </JFXButton>
              <JFXToggleButton fx:id="noAwayBtn" onAction="#handleToggleButtonPressed" prefHeight="60.0" prefWidth="120.0" size="11.0" text="On" textFill="#eda678" toggleColor="#eda678" toggleLineColor="#eba478e2" GridPane.columnIndex="1" GridPane.rowIndex="0" GridPane.rowSpan="2">
                  <font>
                      <Font size="13.0" />
                  </font>
              </JFXToggleButton>
              <JFXToggleButton fx:id="autoQueueBtn" onAction="#handleToggleButtonPressed" prefHeight="60.0" prefWidth="120.0" size="11.0" text="On" textFill="#eda678" toggleColor="#eda678" toggleLineColor="#eba478e2" GridPane.columnIndex="1" GridPane.rowIndex="2" GridPane.rowSpan="2">
                  <font>
                      <Font size="13.0" />
                  </font>
              </JFXToggleButton>
              <JFXToggleButton fx:id="quickReplyBtn" onAction="#handleToggleButtonPressed" prefHeight="60.0" prefWidth="120.0" size="11.0" text="On" textFill="#eda678" toggleColor="#eda678" toggleLineColor="#eba478e2" GridPane.columnIndex="1" GridPane.rowIndex="4" GridPane.rowSpan="2">
                  <font>
                      <Font size="13.0" />
                  </font>
              </JFXToggleButton>
              <Label text="%autoupdate_state" textFill="WHITE" GridPane.rowIndex="6" GridPane.valignment="BOTTOM">
                  <font>
                      <Font size="16.0" />
                  </font>
              </Label>
              <Label text="%autoupdate_message" textFill="#f2efef" wrapText="true" GridPane.rowIndex="7" GridPane.valignment="TOP">
                  <font>
                      <Font size="13.0" />
                  </font>
              </Label>
              <JFXToggleButton fx:id="autoUpdateBtn" onAction="#handleToggleButtonPressed" prefHeight="60.0" prefWidth="120.0" size="11.0" text="On" textFill="#eda678" toggleColor="#eda678" toggleLineColor="#eba478e2" GridPane.columnIndex="1" GridPane.rowIndex="6" GridPane.rowSpan="2">
                  <font>
                      <Font size="13.0" />
                  </font>
              </JFXToggleButton>
           <Label text="%force_english" textFill="WHITE" GridPane.rowIndex="8" GridPane.valignment="BOTTOM">
              <font>
                 <Font size="16.0" />
              </font>
           </Label>
           <Label text="%force_english_message" textFill="#f2efef" wrapText="true" GridPane.rowIndex="9" GridPane.valignment="TOP">
              <font>
                 <Font size="13.0" />
              </font>
           </Label>
           <JFXToggleButton fx:id="force_english_btn" onAction="#handleToggleButtonPressed" prefHeight="60.0" prefWidth="120.0" size="11.0" text="On" textFill="#eda678" toggleColor="#eda678" toggleLineColor="#eba478e2" GridPane.columnIndex="1" GridPane.rowIndex="8" GridPane.rowSpan="2">
              <font>
                 <Font size="13.0" />
              </font>
           </JFXToggleButton>
          </GridPane>
     </content>
  </ScrollPane>
</AnchorPane>

共有1个答案

邹玮
2023-03-14

focusTraversable=“false”添加到gridpane中的每个节点解决了该问题。问题是它在启动时将焦点集中在底部的按钮上,从而将滑块移动到那里。这个解决方案只是简单地使它在没有用户输入的情况下没有任何东西会被随机聚焦。

 类似资料:
  • 问题内容: 我在后台运行一个容器 它迅速退出。但是,如果我在前台运行,则可以正常运行。我使用检查了日志 没有错误。有任何想法吗? DOCKERFILE start-all.sh 问题答案: 一个Docker容器的主要过程完成后退出。 在这种情况下,它将在脚本结束时退出。我对hadoop不太了解,无法在这种情况下告诉您如何做,但是您需要要么在前台运行某些东西,要么使用诸如runit或supervis

  • 使用STS,如果我使用最新的Spring Boot导入Getting Starting项目并选择,它将启动,然后立即关闭。

  • 问题内容: 我正在使用Ajax请求创建聊天,并且试图使消息div滚动到底部没有太多运气。 我将所有内容包装在这个div中: 有没有一种方法可以使用JS将其默认滚动到底部? 有没有一种方法可以在ajax请求后将其滚动到底部? 问题答案: 这是我在网站上使用的内容:

  • 现在的情况是:当内部滚动条滚动到底部时如果继续滚动,外部滚动条不会滚动,需要停顿或者移动鼠标滚动才能触发外层滚动条

  • 在我之前的实习中,我们有一个C#代码(.NET),它有一个控制器,直接连接到数据库(没有服务层)。控制器将获取信息,格式化为JSON并将其交给Angular的控制器,后者将在视图上显示这些信息。 在我现在的实习中,我们不使用Angular。我们使用.cshtml文件。服务层将其信息提供给控制器,控制器格式化模型并将其提供给.cshtml视图,并显示内容。 我的问题: 工作中的每个人都把这两种方法都

  • 这是我的第一个Spring Boot代码。不幸的是,它总是关机。我原本期望它能持续运行,这样我的web客户端就能从浏览器中获取一些数据。 附注。Build.Gradle是错误。 一旦我用粗体取下上面那一行,一切都正常了。我的应用程序上下文现在是正确的。谢谢戴夫