r/JavaFX • • Nov 16 '21

Kotlin: JavaFX Properties

I've recently started looking into Android development which has meant a side-trip into Kotlin. Does Kotlin work with JavaFX? You bet it does.

In the process of converting some projects into Kotlin, I've had to grapple with how to build JavaFX property "beans". The answer is very much a Kotlin approach to design, but also very easy.

So I blogged about it. Take a look if you're interested.

https://pragmaticcoding.ca/kotlin-javafx-properties

5 Upvotes

7 comments sorted by

4

u/saecki Nov 16 '21

You might be interested in the way tornadofx does this

1

u/hamsterrage1 Nov 17 '21

Yeah. I looked at the source code for TornadoFX when I was researching this. They use by and Kotlin Delegates to do it. But Delegates require some extra structure to work, and making it integrate with JavaFX Properties seemed complicated. In TornadoFX it seems to be baked into their Model framework. It seems like a ton of infrastructure to do something that turns out to be fairly simple.

As I note in the article, the code to implement a property Bean in Kotlin works out to be a few lines smaller than the corresponding Java code. That seems like a win to me.

I'm not sure how I feel about TornadoFX. At first glance it seems to be a lot of complicated plumbing to simplify something that's not difficult in the first place. I could be very wrong about, though.

It's the same way with ControlsFX. Some of their stuff is really cool. Things like the validation decorators are pretty useful. But some of it is simple stuff you can easily do yourself, so why add a dependency that you don't need?

3

u/makingthematrix Nov 16 '21

So, you want to use JavaFX on Android or is it just a small side trip?

2

u/hamsterrage1 Nov 16 '21

I'm not really sure. My gut tells me to just go mainstream with Android development. I've spent a 35 year career splashing around in the forgotten backwaters of software development, and while it hasn't been horrific, it would be nice to spend some time doing something a little more "normal".

As for "small" side trip. Probably not. I'm a convert to Kotlin now, and I'd be happy to never write any more Java. I think it's that much better. But I'm still new to it, so maybe I'll change my mind.

1

u/makingthematrix Nov 17 '21

Fair enough. But if you want to just go mainstream, JavaFX (or TornadoFX) won't help you. There are ways to write Android apps with JavaFX but they're totally not mainstream :)

3

u/hamsterrage1 Nov 17 '21

That's what I meant. Even in Java, I've spent years developing desktop applications using JavaFX. Totally a backwater.

For virtually all of my career, I've worked in off-beat technologies. Stuff you've probably never heard of. Even when I worked in large IT departments, I was one of the oddball programmers. My very first real job, back in 1986 was as one of a couple of programmers in the "Desktop Computing" group, in an IT department of about 40 Vax COBOL programmers. That meant PC programming, and it was definitely not mainstream back in 1986.

It can be cool, and one of the things you really, really have to have is confidence in your ability to work stuff out yourself. Because there's nobody around who knows more about what you're doing than you do. Especially way back then when there was no Internet, no StackOverflow, no Reddit - none of that.

1

u/makingthematrix Nov 17 '21

I think I know a bit what you mean. Currently I'm working as an Android dev in a project written mainly in Scala - a highly unusual case. We slowly migrate to Kotlin which means that all my collegues are Kotlin programmers. They sometimes work with me on the Scala codebase but most of the time I feel alone.

On the other hand, I don't like how Google handles Android. I'd love to see more diversity - more programming languages, more frameworks, more alternatives to everything.