java - javafx: How can I make a label automatically updates its text color depending on a String Property? -


basically item class has 2 stringproperty s, namely amount , upordown. values automatically update overtime.

all have done far bind label1's textproperty first stringproperty, amount.

fxlabel1.textproperty().bind(item.amountproperty()); 

question 1:

what want bind color of label's text second string property upordown, i.e. text color gold when upordown up , purple when upordown down. how can achieve this?

question 2:

second, want display image in separate label (not sure if label best option here) depending on string value of upordown. similar exercise, want display image1 in label when upordown up , image2 when upordown down. how can achieve ?

you can use binding :

label.textfillproperty().bind(              bindings.when(upordown.isequalto("up"))                                         .then(color.gold).otherwise(color.purple)); 

similarly, question 2 can use bindings loading image imageview.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -