inputVerifier

Gates keyboard focus leaving this component on verify: while it answers false, Swing keeps the focus where it is, whether the user tabs away, clicks another control, or the application requests the move.

verify takes no argument: the value being validated is the one the composition already declared, so it is read from the caller's own state.

TextField(
port,
onValueChange = { port = it },
modifier = SwingModifier.inputVerifier { port.toIntOrNull() in 1..65535 },
)

A component whose gate must be bypassed - a Cancel button, which has to activate whatever the focused field holds - declares verifyInputWhenFocusTarget false instead. Removing this modifier puts back the verifier the component carried before it was applied.

Return

this chain with the focus gate declared on it.

Parameters

verify

read live, so a fresh lambda each recomposition takes effect immediately.

See also