gpt4 book ai didi

java - 如何在JavaFX自定义进度条中添加发光效果

转载 作者:行者123 更新时间:2023-11-28 05:11:09 24 4
gpt4 key购买 nike

我在 JavaFX 中创建了一个自定义进度条。现在我想在 progressBar 中添加发光效果。

为此,我创建了一个具有高斯模糊效果的椭圆,并将椭圆的 centerX 添加到时间轴中,这样我就可以在进度条中制作发光效果的动画。

这是创建椭圆的代码

public Ellipse glowshape;
DropShadow glowEffect;
SimpleDoubleProperty width;

//create ellipse for gloweffect
public void createEllipse(){

glowshape = new Ellipse(25, 20, 10, 15);
glowshape.setFill(Color.rgb(255,255,255,.7));
glowshape.setEffect(new GaussianBlur(5));
}


public void init(){
indetermination();
setStartAnimation();
createEllipse();

width = new SimpleDoubleProperty(0);
width.bind(this.widthProperty());
setGlowAnimation();
}

这是动画的方法

    public void setGlowAnimation(){

KeyValue value = new KeyValue(glowshape.centerXProperty(),width.doubleValue(),Interpolator.EASE_OUT);

KeyFrame keyframe1 = new KeyFrame(Duration.millis(2000),value);

glow_timeline = new Timeline();
glow_timeline.setCycleCount(Timeline.INDEFINITE);
glow_timeline.setAutoReverse(true);
glow_timeline.getKeyFrames().add(keyframe1);
}

虽然我已经将宽度属性与自定义栏宽度属性绑定(bind),因此椭圆 ce​​nterX 不会超过进度条的当前进度并且应该倒退。但是当动画开始时它不会发生它只是移动一个确定然后卡住了。我认为 Keyvalue 的目标值在动画方法中根本没有更新。

如果有人在这方面帮助我,那就太好了。

最佳答案

Here you are:

    //Create the ProgressBar
ProgressBar progressBar = new ProgressBar();

//Create a drop shadow effect
DropShadow glowEffect= new DropShadow();
glowEffect.setOffsetY(0f);
glowEffect.setOffsetX(0f);
glowEffect.setColor(Color.RED);
glowEffect.setWidth(depth);
glowEffect.setHeight(depth);

progressBar.setEffect(glowEffect); //Apply the glowEffecteffect to the JavaFX ProgressBar

Mention that:

1) 要更改 glowEffect 的宽度/高度,您可以修改 setWidth(..);setHeight();。提及方法 setOffSetX(0); setOffSetY(0f); 用于使 glowEffect 居中。

2) costum progressBar 的过程是相同的,因为它扩展了 Node 类。

Also i add this link in case you need something like:

enter image description here

enter image description here

关于java - 如何在JavaFX自定义进度条中添加发光效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39552152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com