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()
    textArea.setText("Hello, Kotlin/Swing world")
    val scrollPane = JScrollPane(textArea)

    val frame = JFrame("Hello, Kotlin/Swing")
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER)
    frame.setSize(Dimension(600, 400))


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

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.