I have a blog where I talk about programming stuff - mostly JavaFX and Kotlin. I’ve been trying to keep up a steady stream of new content, and I have lots of ideas for topics, but sometimes life gets in the way. This is the first article I’ve posted in a couple of months.

This latest article is the last in a set of three about creating custom controls in JavaFX. The first two were:

They’re not actually required reading for this last article, but they do cover, between them, the most common use cases and approaches for creating custom controls.

But if you’ve ever wondered what Skin was, and how you might alter the look and feel of one of the standard JavaFX controls, then this article might be for you. In it, I look at turning the standard JavaFX ToggleButton into a toggle switch (with a flipper). Under the hood, it’s still a ToggleButton, but by reskinning it, it has a whole new look and feel.

This whole area around Skins and Skinnable is pretty arcane in the JavaFX world. There are very few articles about how to do it. So a word of warning here, everything I know I found out by poking into the source code, looking at other people’s attempts and digging into the little I could find on the web. This is not an explanation of any “official” documentation about how to do this - so there may be some mistakes in the approach. I can say that it works, and it works well.

As far as I can tell, this is the clearest (in my opinion, at least), step-by-step breakdown of how to go about creating a skin that’s available. It’s still not for beginners, but I hope someone finds it useful.

If not, then read the first two articles, I think they’re pretty good too.