property
Declares one Swing property on the component. The property is read as the declaration arrives and written back when the declaration leaves, so a widget that outlives it carries what it did before. Fold the element in only while a value is declared:
private fun SwingModifier.declaredDividerSize(dividerSize: Int?): SwingModifier =
if (dividerSize == null) {
this
} else {
property<JSplitPane, Int>(
name = "dividerSize",
value = dividerSize,
read = { it.dividerSize },
write = { pane, value -> pane.dividerSize = value },
)
}Declare it in a function of its own, not inline at a call site. The property's slot is the class of the write lambda. One write written out once gives every widget declaring that property one slot. The same property written through two lambdas is two slots writing over each other, and a write that captures anything is a fresh instance each pass, written again rather than adopted. A builder may declare several properties, one write each.
Declare only a property this library ships no modifier of its own for. Two slots writing one property each take their own record of what it stood at, and the property is put back from the one leaving last.
Reach for this where a look and feel writes the property onto the widget itself. Where it only publishes the value under a UIManager key and writes nothing onto the widget, read that key and pass the answer as value: there is nothing to put back, so no element is needed.
Return
this modifier with name declared on it.
Parameters
the Swing property being written. It labels the property in an error and wherever a tool shows the modifier; write is what identifies the slot.
the value to write while this declaration stands.
answers with the value the component holds, taken as the declaration arrives.
what the component is held to once this declaration leaves. RestorePolicy.EverythingWritten, the default, holds it to carrying read's answer again. RestorePolicy.DeclaredPropertyOnly holds it to name alone, for a write a look and feel derives a property of its own from. RestorePolicy.None is for a property the component offers no way to give back - one whose setter refuses the value read answered with, or rebuilds the component's UI - and write says what the component keeps instead.
Declares one Swing property on the component, naming the component type as a value.
The same contract as the reified overload above, with targetType - the thing that one reifies - spelled out. Reach for this when the component type is only known as a KClass.
Return
this modifier with name declared on it.
Parameters
the Swing property being written. It labels the property in an error and wherever a tool shows the modifier; write is what identifies the slot.
the value to write while this declaration stands.
answers with the value the component holds, taken as the declaration arrives.
what the component is held to once this declaration leaves.