2017-02-25 57 views
0

我想自動顯示滾動條時,窗口大小調整爲銀白楊看到所有的矩形我怎樣才能讓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> 

回答

0

是的,有:只需使用FlowPane作爲ScrollPane內容,並使用fitToWidth使使ScrollPane設置內容的寬度根據可用寬度...

<?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> 
+0

感謝您的幫助 –