JavaFX Marquee exits node

1

I have a problem with the "Marquee" animation in JavaFx. This is the situation: I have an HBox with three nodes and in the central node I have a Label with a text that I want to make the animation, which works perfectly, but when it goes to the left and leaves the node, I need it to disappear and it does not show the text in the next noded

I leave you an image of the problem:

My declaration of 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);

The animation:

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

And how do I define my product node:

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);

I hope you have enough information

Thank you!

    
asked by accnono 10.11.2016 в 10:18
source

1 answer

0

This answer has been given to me by @fabian from the StackOverflow.com community (English). I just put it and translate it in case someone is interested, it has worked for me. (Thanks @fabian)

Just add a Rectangle as clip for the panel product and "bindea" (bind) its size to the size of the panel:

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

This will assure you that no descendant of product is drawn outside the limits of this node.

    
answered by 10.11.2016 / 16:06
source