JavaFX Marquee走出我的节点 [英] JavaFX Marquee go out of my node
问题描述
我使用JavaFX的Marquee动画出现问题。我有一个带有三个节点的HBox,在第二个节点中,我有一个文本节点,我需要进行Marquee转换,但是当文本从第二个节点出来时,我看不到它。
I have a issue with my Marquee animation with JavaFX. I have a HBox with three Nodes and in the second node I have a Text node inside that I need do the Marquee transformation, but when the text goes out of the second node I need it doesn't be visible.
我将设置一张图片来显示我的问题(文本在白色区域可见)。
I'll go to set a picture to show my issue (the text is visible in the white area).
我的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);
以及我如何定义产品节点:
And how 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);
希望这是足够的信息。
谢谢!
推荐答案
只需添加矩形
作为为
并将其大小绑定到窗格的大小: product
窗格剪切
Simply add a Rectangle
as clip
for the product
pane and bind it's size to the size of the pane:
Rectangle clip = new Rectangle();
product.layoutBoundsProperty().addListener((observable, oldValue, newValue) -> {
clip.setWidth(newValue.getWidth());
clip.setHeight(newValue.getHeight());
});
product.setClip(clip);
这将确保没有产品的后代
绘制在此节点的边界之外。
This will make sure no descendants of product
are drawn outside the bounds of this node.
这篇关于JavaFX Marquee走出我的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!