A Kotlin/Swing GUI example (uses JFrame, JScrollPane, and JTextArea)

Here’s a little Kotlin example that uses Java Swing, including a JFrame, JScrollPane, and JTextArea:

import java.awt.BorderLayout
import java.awt.Dimension
import javax.swing.JFrame
import javax.swing.JScrollPane
import javax.swing.JTextArea

fun main(args: Array<String>) {

    val textArea = JTextArea("Hello, Kotlin/Swing world")
    val scrollPane = JScrollPane(textArea)

    val frame = JFrame("Hello, Kotlin/Swing")
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER)
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
    frame.setSize(Dimension(600, 400))
    frame.setLocationRelativeTo(null)
    frame.setVisible(true)

}

Kotlin and Scala are similar in many ways, so this is a simple port of my Scala Swing example.