Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda