Over a million developers have joined DZone.

ListMenu JavaFX Control

How to build a list menu using the JavaFX framework for Kotlin — TornadoFX.

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

While working on an upcoming JavaFX Framework for Kotlin — TornadoFX, I needed a HTML5 like menu for a demo application. I thought it would be easy to reuse existing components like a VBox with ToggleButtons in it, but there were a lot of corner cases involved in making it behave like an actual menu.

Instead I opted to create a reusable component for web-like menus with configurable orientatioImage titlen and icon position. I also wanted to solve another problem I ran into with the ToggleButton approach — not all icons, especially in icon fonts — are the same width. This makes it quite difficult to align the button text in relation to the other buttons. I therefore added a custom css property called -fx-graphic-fixed-size to deal with icons of different width or height, depending on the orientation of the menu.

There is also an active pseudo state to distinguish the active menu item visually. You can listen to the menu's active property to react on changes.

You can find it in my TornadoFX Controls repo on GitHub, and in Maven central:

<dependency>
    <groupId>no.tornado</groupId>
    <artifactId>tornadofx-controls</artifactId>
    <version>1.0</version>
</dependency>

For now there is only this single control in there, but I plan to add more in the future.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:
javafx ,java ,ui components

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}