使所有元素(包括2个列表视图)在JavaFX中一起滚动

huangapple go评论80阅读模式
英文:

Make all elements (including 2 list views) scroll together in JavaFX

问题

<VBox xmlns="http://javafx.com/javafx/11" xmlns:fx="http://javafx.com/fxml/1">
   <StackPane prefHeight="30.0" prefWidth="200.0" styleClass="stack-welcome" VBox.vgrow="NEVER">
      <children>
         <Label styleClass="label-welcome" text="Hi! I'm Volant :)" />
      </children>
   </StackPane>
   <StackPane prefHeight="15.0" prefWidth="200.0" styleClass="stack-header" VBox.vgrow="NEVER">
      <children>
        <Label styleClass="label-header" text="TRIP LIST" />
      </children>
   </StackPane>

   <StackPane prefHeight="15.0" prefWidth="200.0" styleClass="trip-list-header" style="-fx-border-width: 0px 0px 2px 0px" VBox.vgrow="NEVER">
      <children>
         <Label styleClass="label-header" text="UPCOMING TRIPS" />
      </children>
   </StackPane>
   <ListView fx:id="tripListViewUpcoming" prefWidth="247.0" style="-fx-background-color: #fff;" VBox.vgrow="ALWAYS" />

   <StackPane prefHeight="15.0" prefWidth="200.0" styleClass="trip-list-header" style="-fx-border-width: 2px 0px 2px 0px" VBox.vgrow="NEVER">
      <children>
         <Label styleClass="label-header" text="PAST TRIPS" />
      </children>
   </StackPane>
   <ListView fx:id="tripListViewPast" prefWidth="247.0" style="-fx-background-color: #fff;" VBox.vgrow="ALWAYS" />

</VBox>
英文:

I have a VBox, and within the VBox are some elements including 3 headers (3 stack panes) and 2 list views, is it possible to make everything in the VBox scroll together?

Here is an image of my application

使所有元素(包括2个列表视图)在JavaFX中一起滚动

This is the FXML code for this view

&lt;VBox xmlns=&quot;http://javafx.com/javafx/11&quot; xmlns:fx=&quot;http://javafx.com/fxml/1&quot;&gt;
   &lt;StackPane prefHeight=&quot;30.0&quot; prefWidth=&quot;200.0&quot; styleClass=&quot;stack-welcome&quot; VBox.vgrow=&quot;NEVER&quot;&gt;
      &lt;children&gt;

         &lt;!-- WELCOME MESSAGE --&gt;
         &lt;Label styleClass=&quot;label-welcome&quot; text=&quot;Hi! I&#39;m Volant :)&quot; /&gt;
      &lt;/children&gt;
   &lt;/StackPane&gt;
   &lt;StackPane prefHeight=&quot;15.0&quot; prefWidth=&quot;200.0&quot; styleClass=&quot;stack-header&quot; VBox.vgrow=&quot;NEVER&quot;&gt;
      &lt;children&gt;
        &lt;Label styleClass=&quot;label-header&quot; text=&quot;TRIP LIST&quot; /&gt;
      &lt;/children&gt;
   &lt;/StackPane&gt;

   &lt;StackPane prefHeight=&quot;15.0&quot; prefWidth=&quot;200.0&quot; styleClass=&quot;trip-list-header&quot; style=&quot;-fx-border-width: 0px 0px 2px 0px&quot; VBox.vgrow=&quot;NEVER&quot;&gt;
      &lt;children&gt;
         &lt;Label styleClass=&quot;label-header&quot; text=&quot;UPCOMING TRIPS&quot; /&gt;
      &lt;/children&gt;
   &lt;/StackPane&gt;
   &lt;ListView fx:id=&quot;tripListViewUpcoming&quot; prefWidth=&quot;247.0&quot; style=&quot;-fx-background-color: #fff;&quot; VBox.vgrow=&quot;ALWAYS&quot; /&gt;

   &lt;StackPane prefHeight=&quot;15.0&quot; prefWidth=&quot;200.0&quot; styleClass=&quot;trip-list-header&quot; style=&quot;-fx-border-width: 2px 0px 2px 0px&quot; VBox.vgrow=&quot;NEVER&quot;&gt;
      &lt;children&gt;
         &lt;Label styleClass=&quot;label-header&quot; text=&quot;PAST TRIPS&quot; /&gt;
      &lt;/children&gt;
   &lt;/StackPane&gt;
   &lt;ListView fx:id=&quot;tripListViewPast&quot; prefWidth=&quot;247.0&quot; style=&quot;-fx-background-color: #fff;&quot; VBox.vgrow=&quot;ALWAYS&quot; /&gt;

&lt;/VBox&gt;

答案1

得分: 0

我成功地通过使用滚动窗格包裹VBox,并设置 scrollPane.setFitToWidth(true); 来使整个VBox一起滚动。

英文:

I manged to make the whole VBox scroll together by wrapping the VBox with a scrollPane and setting scrollPane.setFitToWidth(true);

huangapple
  • 本文由 发表于 2020年4月4日 22:05:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/61029298.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定