Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda