简体   繁体   English

为什么我的javafx滚动窗格立即滚动到底部?

[英]Why is my javafx scrollpane immediately scrolling to the bottom?

I have a settings panel which is not resizeable that was getting crowded so I decided to add the gridpane which contains the settings to a scrollpane. 我有一个无法调整大小的设置面板,变得拥挤不堪,所以我决定将包含设置的网格窗格添加到滚动窗格中。 The issue is that the scrollpane starts at the bottom when the application starts up. 问题是,启动应用程序时,滚动窗格从底部开始。 The weird thing is that I set the HValue to 0 to it should start at the top. 奇怪的是,我将HValue设置为0,它应该从顶部开始。 This is a gif showing it in scene builder: https://gyazo.com/f10a1641b8357e4fc30cd180c0425dae No code is interacting with the scrollpane at all and as you can see the scene builder preview window also has the same issue so it has something to do with the FXML. 这是在场景生成器中显示的gif: https ://gyazo.com/f10a1641b8357e4fc30cd180c0425dae根本没有代码与滚动窗格交互,并且您可以看到场景生成器预览窗口也存在相同的问题,因此与FXML。 To reproduce it you can simply setup a javafx project yourself using the fxml shared below, then just run it and see how the scrollbar skips to the bottom. 要重现它,您可以使用下面共享的fxml自己简单地设置一个javafx项目,然后运行它并查看滚动条如何跳到底部。 The full FXML file: https://pastebin.com/aS3Dn3pH . 完整的FXML文件: https ://pastebin.com/aS3Dn3pH。 Snippet of only the scrollpane stuff: 仅滚动窗格内容的片段:

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

Adding focusTraversable="false" to every node in the gridpane solved the issue. focusTraversable="false"中的每个节点添加focusTraversable="false"可以解决此问题。 The issue was that it was focussing on the button at the bottom on startup thus moving the slider there. 问题是它在启动时专注于底部的按钮,因此将滑块移到那里。 This solution simply makes it so that nothing gets randomly focussed without user input anymore. 该解决方案简单地做到了这一点,从而无需用户输入,任何事物都可以随意聚焦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM