Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
format text of Label

I have a label in a view that is controlled by a integer property, when the value is negative it displays with a minus sign, when the value is positive it does not. However, I would like the Label to display "+5", "-3" ...

take the following code as an example

import javafx.beans.property.SimpleIntegerProperty
import tornadofx.*

class MyView : View() {

   val negProp = SimpleIntegerProperty(-3) // this prop is in a ItemViewModel
   val posProp = SimpleIntegerProperty(+4) // this prop is in a ItemViewModel

    override val root = hbox {
        label(negProp)      // shows - 3
        label(posProp)      // shows 4
    }
}

Is there a way I can format the text once the property changes ? Thank you.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You could create a stringbinding which holds the value you want to display in the label and then bind the label's value property to that:

val prop = SimpleIntegerProperty(1)
val propDesc = prop.stringBinding { "%+d".format(it) }

Now you can do:

label(propDesc)

The label will update whenever the property changes value.

You can of course also inline it:

label(prop.stringBinding { "%+d".format(it) })
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!