2016-09-17 81 views
0

我創建JavaFX中的自定義進度條。現在我想在progressBar中添加發光效果。如何添加發光效果在JavaFX定製進度

爲此,我已創建了高斯模糊效果的橢圓,並添加橢圓的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(); 
} 

這是雖然我綁定與自定義欄width屬性width屬性爲動畫

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

的方法,這樣的橢圓的centerX沒有按不會超出進度條的當前進度,並且應該反轉回來。但是當動畫開始時它不會發生,它只是移動一定的然後卡住。我認爲Keyvalue的目標值在動畫方法中根本沒有更新。

,如果有人可以幫助我在這這將是巨大的。

+0

也許你可以共享一個代碼片斷展示瞭如何創建進度條? – davidrpugh

回答

0

在這裏,你是:

//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 

提及的是:

1)改變glowEffect的寬度/高度可以修改setWidth(..);setHeight(); .Mention那方法setOffSetX(0);setOffSetY(0f);用於居中glowEffect

2)的步驟是用於costum progressBar一樣它延伸Node類。

此外,我添加此link的情況下,你需要這樣的東西:

enter image description here

enter image description here

+0

嗨, 我已經試過你的代碼,但它沒有work.Drop陰影在節點外創建一個效果。 不過,我已創建了高斯模糊效果的橢圓,然後開始動畫以動畫整個進度條中progress.I也結合鍵值目標與進度條的寬度值光暈效果property.But它不工作它也只是稍微移動一下而卡住了。目標值不會更新。我不明白爲什麼會發生這種情況。您可以幫我解決這個問題 –