Kotlin ui dsl

From JetBrains/intellij-community · View interactive version

Kotlin ui dsl is an AI agent skill from the GitHub repository JetBrains/intellij-community. Write IntelliJ dialogs and settings with Kotlin UI DSL v2 panels.

How to use this skill

Skill file

Kotlin UI DSL

Use Kotlin UI DSL (com.intellij.ui.dsl.builder, "version 2") for new IntelliJ forms: dialogs, settings pages, and form-like tool-window content. panel { } returns a DialogPanel with layout, data binding, and validation wired together.

Version 1 (the com.intellij.ui.layout builder: LayoutBuilder, CellBuilder, PropertyBinding, noteRow, titledRow, ...) is removed. Never write against it. ComponentPredicate and ValidationInfoBuilder in the same package are v2 support code.

For component architecture (state flow, EDT, lifecycle) apply the Swing component architecture skill; for accessibility review apply the UI accessibility skill.

Sources and live examples

Before inventing a pattern, check whether a Demo*.kt or sandbox panel already demonstrates it.

Core model

A panel is a grid built row by row:

val panel: DialogPanel = panel {
  row(MyBundle.message("label.host")) {          // "Host:" — sets labelFor + mnemonics + accessible context
    textField()
      .align(AlignX.FILL)
      .bindText(model::host)
  }
  row(MyBundle.message("label.port")) {
    intTextField(range = 0..65535)
      .bindIntText(model::port)
  }
  row {
    checkBox(MyBundle.message("checkbox.use.auth"))
      .bindSelected(model::useAuth)
  }
}

Rows, labels, and row layout

Components (Row factories)

Always prefer a factory over cell(JBTextField()) — factories apply platform defaults (widths, gaps, group membership):

Tune components via .applyToComponent { ... }. Text-field width: .columns(COLUMNS_TINY|COLUMNS_SHORT|COLUMNS_MEDIUM|COLUMNS_LARGE) (6/18/25/36).

Structure: groups and multi-column

panel {
  group(MyBundle.message("group.server")) { ... }          // titled block, own grid, vertical gaps around
  groupRowsRange(title) { ... }                            // titled block sharing the parent grid
  collapsibleGroup(title) { ... }                          // collapsible; title is focusable, supports mnemonics
  rowsRange { ... }                                        // invisible range for batch visibleIf/enabledIf, parent grid
  indent { ... }                                           // standard left indent
  separator()                                              // plain line; for a titled line use group/groupRowsRange
  panel { ... }                                            // sub-panel: full width, own grid
  twoColumnsRow({ checkBox(...) }, { checkBox(...) })      // and threeColumnsRow(...)
}

```kotlin

buttonsGroup(MyBundle.message("group.color")) {

for (value in Color.entries) {

row { radioButton(value.displayName, value) }

}

}.bind(model::color) // radioButton value arguments must match the property type

```

Sizing, alignment, gaps

Data binding

Bindings connect a component to a property; the property is written only on DialogPanel.apply(), while reset() and isModified() come for free:

| Component | Binding |

|---|---|

| checkBox, any AbstractButton | bindSelected(model::flag) |

| textField & other text components | bindText(model::text) / bindText(getter, setter) |

| intTextField | bindIntText(model::count) |

| comboBox | bindItem(model::item.toNullableProperty()) |

| spinner | bindIntValue(model::value) / bindValue(model::double) |

| slider | bindValue(model::value) |

| textFieldWithBrowseButton | bindText(model::path) |

| buttonsGroup | .bind(model::choice) — radio buttons carry values |

| segmentedButton | .bind(property) |

| custom cell(c) | .bind(componentGet, componentSet, prop) |

Validation

Two rule styles on Cell:

// Stable API: ValidationInfoBuilder receiver — error(...) / warning(...)
textField()
  .validationOnInput { if (it.text.toIntOrNull() == null) error(MyBundle.message("error.not.a.number")) else null }
  .validationOnApply { if (it.text.isBlank()) error(MyBundle.message("error.specify.value")) else null }

// Newer API (experimental, used across the platform; will eventually be renamed `validation`)
textField().cellValidation {
  addInputRule(MyBundle.message("error.contains.digits"), level = Level.WARNING) { it.text.any(Char::isDigit) }
  addApplyRule(MyBundle.message("error.must.not.be.empty")) { it.text.isNullOrEmpty() }   // condition true = problem
  enabledIf(someCheckBox.selected)
}

Dynamic UI

```kotlin

lateinit var enableAll: Cell<JBCheckBox>

row { enableAll = checkBox(MyBundle.message("checkbox.enable")) }

indent {

row { checkBox(MyBundle.message("checkbox.option1")) }

}.enabledIf(enableAll.selected)

```

List and combo renderers

Never hand-write ListCellRenderers for combo boxes and JBList. Use the DSL from com.intellij.ui.dsl.listCellRenderer:

comboBox(items, textListCellRenderer { it?.displayName })          // simple text

comboBox(items, listCellRenderer {                                  // rich rows
  icon(value.icon)
  text(value.name)
  text(value.detail) { foreground = greyForeground }
  separator { text = "Group" }                                      // section separator
})

Settings pages

Hard rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.