2016-11-10 44 views
1

我的我的Marquee動畫與JavaFX有問題。我有一個HBox和三個節點,第二個節點中有一個Text節點,我需要做Marquee轉換,但是當文本離開第二個節點時,我需要它不可見。JavaFX Marquee走出我的節點

我會去設置一張圖片來顯示我的問題(文本在白色區域中可見)。

text introduces inside white node

我HBOX代碼:

HBox bill = new HBox(0); 
    bill.getChildren().addAll(logoPane,product,total); 
    bill.setBackground(new Background(new BackgroundFill(Color.web("#FFFFFF"), CornerRadii.EMPTY, Insets.EMPTY))); 
    bill.setHgrow(product, Priority.ALWAYS); 

動畫:

timelineAnimation = new Timeline(); 
    final KeyValue kv = new KeyValue(productLabel.translateXProperty(), -1000); 
    final KeyFrame kf = new KeyFrame(Duration.millis(2000), kv); 
    timelineAnimation.getKeyFrames().add(kf); 

我如何定義我的產品節點:

productLabel.setFont(new Font("Times New Roman",30)); 

    product = new StackPane(); 
    product.setMaxWidth(2000); 
    product.setMaxHeight(100); 
    product.setMinWidth(574); 
    product.setMinHeight(100); 

    product.getChildren().add(productLabel); 
    product.setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY))); 
    product.setAlignment(productLabel, Pos.CENTER); 

希望這已經足夠了信息離子。

謝謝!

回答

1

只需添加一個Rectangle作爲clipproduct窗格,它的大小結合到窗格的大小:

Rectangle clip = new Rectangle(); 
product.layoutBoundsProperty().addListener((observable, oldValue, newValue) -> { 
    clip.setWidth(newValue.getWidth()); 
    clip.setHeight(newValue.getHeight()); 
}); 
product.setClip(clip); 

這將確保沒有product後裔在此節點的範圍之外繪製。

+0

不錯,它的作品!謝謝@fabian – accnono