2016-11-22 28 views
0

我需要水平幫助在TilePane(包含在ScrollPane中)插入對象。它會水平插入,直到到達ScrollPane的末尾,然後開始添加到ScrollPane的下一行。這是什麼樣子:JavaFX水平添加TilePane中的對象(TilePane在ScrollPane中)

enter image description here

盒子是ScrollPaneTilePane是阻礙所有圖像。

基本上,我想要TilePane繼續添加到右側,並讓ScrollPane顯示一個水平滾動條。

這裏是我的代碼:

private void start() 
{ 
    @FXML private ImageView bigImage; 
    @FXML private ScrollPane scrollPane; 
    @FXML private TilePane tilePane; 

    // Setup scrollpane 
    scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); 
    scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);  
    tilePane.setHgap(15); 

    for(int i = 0; i < 10; i++) 
    { 
     ImageView imageView = new ImageView(bigImage.getImage()); 
     imageView.setFitWidth(100); 
     imageView.setFitHeight(100); 

     tilePane.getChildren().add(imageView); 
    } 

    //scrollPane.setFitToWidth(true); 
    scrollPane.setContent(tilePane); 
} 

FXML:

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

<?import javafx.scene.control.ScrollPane?> 
<?import javafx.scene.image.Image?> 
<?import javafx.scene.image.ImageView?> 
<?import javafx.scene.layout.AnchorPane?> 
<?import javafx.scene.layout.TilePane?> 

<AnchorPane prefHeight="700.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.PhotoController"> 

    <children>  
     <ImageView fx:id="bigImage" fitHeight="441.0" fitWidth="534.0" layoutX="35.0" layoutY="52.0" pickOnBounds="true"> 
     <image> 
      <Image url="@../../../../../../Pictures/Wallpaper02.jpg" /> 
     </image> 
     </ImageView> 

     <ScrollPane fx:id="scrollPane" layoutX="35.0" layoutY="528.0" prefHeight="140.0" prefWidth="820.0"> 
     <content> 
      <TilePane fx:id="tilePane" prefHeight="137.0" prefWidth="817.0" /> 
     </content> 
     </ScrollPane> 
    </children> 

</AnchorPane> 

我怎麼能完成我想做什麼?任何幫助,將不勝感激。謝謝!

回答

0

可以使用CCS財產「重複」與你的背景是這樣,它會做所有的工作:

-fx-background-image:url("Image.png"); 
-fx-background-repeat:repeat; 

更多修飾看在Docs與背景屬性。

+0

這沒有做任何事情。圖像仍然插入到下一行而不是右側。 – syy