Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Default value for SimpleDoubleProperty when binding it to a TextField #1337

Closed
AIGLEZMA opened this issue Jul 18, 2021 · 1 comment
Closed

Comments

@AIGLEZMA
Copy link

Hi there, when i bind a TextField to a SimpleDoubleProperty it's text (of the textfield) is 0, how can i override that to be empty

@yamert89
Copy link
Contributor

You can use bind() extension function with converter.

val doubleProperty = SimpleDoubleProperty() as Property<Double>
TextField().bind(property = doubleProperty, converter = CustomDoubleStringConverter())
class CustomDoubleStringConverter: DoubleStringConverter(){
    override fun toString(value: Double?): String {
        return if(value == null || value == 0) "" else value.toString()
    }
}

@AIGLEZMA AIGLEZMA closed this as completed Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants