DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Flight Recorder: Examining Java and Kotlin Apps
  • Deploying a Kotlin App to Heroku
  • Develop a Secure CRUD Application Using Angular and Spring Boot
  • Building a Simple Todo App With Model Context Protocol (MCP)

Trending

  • Optimize Deployment Pipelines for Speed, Security and Seamless Automation
  • Rethinking Recruitment: A Journey Through Hiring Practices
  • From Zero to Production: Best Practices for Scaling LLMs in the Enterprise
  • AI’s Role in Everyday Development
  1. DZone
  2. Coding
  3. Java
  4. A New JavaFX App Framework for Kotlin — TornadoFX

A New JavaFX App Framework for Kotlin — TornadoFX

How to use the TornadoFX MVC framework with JetBrains' Kotlin JVM language.

By 
Edvin Syse user avatar
Edvin Syse
·
Jan. 28, 16 · Opinion
Likes (9)
Comment
Save
Tweet
Share
30.5K Views

Join the DZone community and get the full member experience.

Join For Free

Image title

TornadoFX is a JavaFX application framework for Kotlin, the new statically typed JVM language from JetBrains.

Why Yet Another Framework?

Kotlin interoperates perfectly with Java, so writing JavaFX apps with Kotlin is already a pleasure. However, TornadoFX makes use of some very interesting language features of Kotlin that enables even more concise and beautiful code without hiding any features of the JavaFX API.

Quick Overview

TornadoFX is an MVC framework. A View contains the root node of the UI as well as the view logic. Controllers contain the business logic. Elegant async support ensures that long running tasks run in a background thread and that the result is applied on the UI thread.

It comes with a REST client and built in JSON support. Other features include dependency injection, automatic FXML view loading, type safe builders, and various enhancements to standard JavaFX API's made possible with Kotlin's extension functions.

What It's Not

TornadoFX does not have any visual components. There is no docking framework, no special toolbar or action interfaces for you to implement like what you would find in RCP frameworks like Eclipse RCP and NetBeans RCP. While such frameworks are great for some types of applications, they often make you carry baggage you don't need. They also add to the learning curve.

You can learn TornadoFX in an afternoon and be instantly productive because you are using your existing JavaFX knowledge on top of a very light framework that doesn't force you into a lot of new patterns. The principal design goal is to provide just what you need, without getting in the way.

What Does it Look Like?

Here are some code samples to give you a feel for the framework.

Hello World View

class HelloWorld : View() {
    override val root = HBox(Label("Hello world")) 
}

View Loaded From HelloWorld.fxml With Additional init Operations

class HelloWorld : View() {
    override val root: HBox by fxml()
val label: Label by fxid()

    init {
        label.text = "Hello world"
    }
}

A Controller That Makes a REST Call and Converts the JSON Result to a List of Customer Objects

class CustomerController : Controller() {
    val api : Rest by inject()

    fun listCustomers(): ObservableList<Customer> = 
        api.get("path/to/customers").list().toModel() 
}

Add a Row to a GridPane

grid.row {
    label("Name") {
        addClass("fieldLabel")
    }
    textfield {
        promptText = "Enter your name"
        textProperty().bindBidirectional(user.name)
    }
}

Add User Selection Listener to a TableView

contactsTable.onSelectionChange {
    editContact(it)
}

Run a Background Job and Update the UI When Finished

background {
    customerController.listCustomers()
} ui {
    customerTable.items = it
}

Download

TornadoFX is available at Maven Central.

<dependency>
    <groupId>no.tornado</groupId>
    <artifactId>tornadofx</artifactId>
    <version>1.4.1</version>
</dependency>

Take It For a Spin

You can clone the example application repository on GitHub to get a basic skeleton up and running quickly.

Head over to the Wiki for complete Documentation and more usage examples. I'd love to get your feedback!

Enjoy JavaFX and Kotlin. :)

Application framework JavaFX Kotlin (programming language) app

Opinions expressed by DZone contributors are their own.

Related

  • Flight Recorder: Examining Java and Kotlin Apps
  • Deploying a Kotlin App to Heroku
  • Develop a Secure CRUD Application Using Angular and Spring Boot
  • Building a Simple Todo App With Model Context Protocol (MCP)

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!