Skip to content

Utilities

Thosea edited this page Jun 22, 2025 · 1 revision

Utilities

KSwing also has some general-purpose Swing utilities.

Size Extensions

These allow you to change how big a component should be. These methods are provided:

  • kCapSize / kCapWidth / kCapHeight - changes maximumSize
  • kCapSizeToPreferred / kCapWidthToPreferred / kCapHeightToPreferred - changes maximumSize partially or entirely to preferredSize. useful on layouts that let a component span its entire maximum size
  • kPreferSize - changes preferredSize

Font Extensions

For slightly easier font editing, these properties (also as builder functions) are provided:

  • kFontSize
  • kBold
  • kItalic
  • kFontName
  • kFontAttr (function-only)

Example:

KLabel("Hi There") {
	kFontSize = 22f
	kBold = true
	kFontName = "Comic Sans MS"
	kFontAttr(TextAttribute.UNDERLINE to TextAttribute.UNDERLINE_ON)
}
// or
KLabel("Hi There").kFontSize(22f).kBold(true)

Misc Extensions

  • kRevalidateAndRepaint - shortcut for revalidate and repaint
  • kDocChangeListener (extension of Document) - adds a listener that is invoked when any part of the document changes in any way
val state = KState<String>() // nullable
KLazyTextField {
	document.kDocChangeListener {
		state.value = text
	}
}

Non-Extensions

  • KConstants has kEmptyBorder and kEmptyColor
  • KProperties wraps some Swing/AWT system properties for convenience (i.e. KProperties.useOpengl = true)
  • kBagConstraints(...) is a wrapper for GridBagConstraints using default parameters
  • kImageFromIcon / kBufferImageFromIcon gets an Image from an Icon

Clone this wiki locally