2016-11-10 39 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