Skip to content

muqhc/frogui

Repository files navigation

frogui

the kotlin library providing DSL for Swing

add dependency

Gradle Kotlin DSL

build.gradle.kts

repositories {
    mavenCentral()
}

dependencies {
    implementation("io.github.muqhc:frogui:0.2.0")
}

examples

to use....

import io.github.muqhc.frogui.*

build JPanel (by using frogui dsl)

val myPane = borderLayout {

    //add component to 'north'
    north = JButton("I'm north!")
    
    //add component to 'south'
    south = JButton("I'm south!")

    //add component to 'center'
    center = gridLayout { // add inner panel
        layout.columns = 2

        //use 'unary plus' to add component
        +JButton("I'm the First!")

        +flowLayout { // add inner panel
            +JButton("[ 1 ]")
            +JButton("[ 2 ]")
            +JButton("[ 3 ]")
        }
    }
}

example_image.png


make your own custom JPanel

class CounterPanel() : JPanel() {
    var value = 0

    val device = JLabel("$value").apply { horizontalAlignment = JLabel.CENTER }

    init {
        // ==== Here !!! ====
        gridLayout {
            layout.rows = 2
            +device
            +gridLayout {
                layout.columns = 2
                +JButton("-").apply { addActionListener { update(value - 1) } }
                +JButton("+").apply { addActionListener { update(value + 1) } }
            }
        }
        // ==========
    }

    fun update(value: Int) {
        this.value = value
        device.text = value.toString()
    }
}

example_video.gif


( you can also extend it )
val customPane = CounterPanel() gridLayout {
    layout.rows = 3
    +JButton("Reset!").apply { addActionListener { panel.update(0) } }
}

example_video2.gif


About

the kotlin library providing DSL for Swing

Topics

Resources

License

Stars

Watchers

Forks

Languages