Package-level declarations

Types

Link copied to clipboard
class CallbackRegistration<T : Component, C : Any, L : Any>(adapter: (current: () -> C) -> L, registration: ListenerRegistration<T, L>)

A registration together with the adapter that builds the listener riding it: what a modifier taking a callback of type C, rather than a listener of type L, registers.

Link copied to clipboard
class ListenerRegistration<T : Component, L : Any>(name: String, attach: (component: T, listener: L) -> Unit, detach: (component: T, listener: L) -> Unit, key: Any? = null)

Where a listener is registered: the add/remove pair of one event source on components of type T, for listeners of type L.

Functions

Link copied to clipboard

Attaches an ActionListener (addActionListener/removeActionListener) to a component that fires action events (AbstractButton - so JButton, JCheckBox, ... -, JTextField, JComboBox, JFileChooser, and the AWT Button, TextField, and List).

Runs onAction on the action event of a component that fires one - the same components actionListener lists.

inline fun <T : Component> SwingModifier.actionListener(noinline onAction: T.(ActionEvent) -> Unit): SwingModifier

Runs onAction on the action event of a component of type T that fires one, with that component as this.

Runs onAction on the action event of a component of type targetType that fires one, with that component as this. An event sourced anywhere else is refused; see listener.

Link copied to clipboard

Attaches an AdjustmentListener (addAdjustmentListener/removeAdjustmentListener) to a scrollbar (javax.swing.JScrollBar, java.awt.Scrollbar).

Runs onAdjustment whenever a scrollbar's value changes - the scrollbars adjustmentListener lists.

Link copied to clipboard

Attaches a CaretListener (addCaretListener/removeCaretListener). Requires a JTextComponent target (JTextField, JTextArea, ...). Each event carries the caret offset and the selection anchor, so one listener observes both the caret position and the selected range.

Runs onCaretUpdate whenever the caret moves or the selection changes. Requires a JTextComponent target.

Link copied to clipboard

Attaches a ChangeListener (addChangeListener/removeChangeListener) to a component that fires change events (JSlider, JSpinner, JTabbedPane, JProgressBar, AbstractButton, JViewport, JColorChooser). A color chooser publishes its change events through its selectionModel, and the registration follows that model when the chooser is given another one.

Runs onChange on the change event of a component that fires one - the widgets changeListener lists.

inline fun <T : Component> SwingModifier.changeListener(noinline onChange: T.(ChangeEvent) -> Unit): SwingModifier

Runs onChange on the change event of a component of type T that fires one, with that component as this.

Runs onChange on the change event of a component of type targetType that fires one, with that component as this. An event sourced anywhere else is refused; see listener.

Link copied to clipboard

Attaches a ComponentListener (addComponentListener/removeComponentListener).

Runs onComponentChange whenever the component is resized, moved, shown or hidden. Declare the four separately to tell them apart.

fun SwingModifier.componentListener(onComponentResized: (ComponentEvent) -> Unit = UNDECLARED, onComponentMoved: (ComponentEvent) -> Unit = UNDECLARED, onComponentShown: (ComponentEvent) -> Unit = UNDECLARED, onComponentHidden: (ComponentEvent) -> Unit = UNDECLARED): SwingModifier

Runs each lambda on the change it is declared for. A change left undeclared reports nowhere.

Link copied to clipboard

Attaches a ContainerListener (addContainerListener/removeContainerListener). Requires a Container target.

Runs onChildrenChange whenever a child is added to or removed from the container. Requires a Container target.

fun SwingModifier.containerListener(onComponentAdded: (ContainerEvent) -> Unit = UNDECLARED, onComponentRemoved: (ContainerEvent) -> Unit = UNDECLARED): SwingModifier

Runs onComponentAdded when a child joins the container and onComponentRemoved when one leaves. Requires a Container target. A direction left undeclared reports nowhere.

Link copied to clipboard

Attaches a DocumentListener to the text component's document (document.addDocumentListener). Requires a JTextComponent target (JTextField, JTextArea, ...). The listener observes the document the component currently holds, following it when the component swaps one in.

Runs onDocumentChange for every change to the text component's document - an insertion, a removal and a change of attributes alike. Requires a JTextComponent target, and observes the document the component currently holds, following it when the component swaps one in - as a JEditorPane does when its content type changes.

fun SwingModifier.documentListener(onInsert: (DocumentEvent) -> Unit = UNDECLARED, onRemove: (DocumentEvent) -> Unit = UNDECLARED, onChange: (DocumentEvent) -> Unit = UNDECLARED): SwingModifier

Runs onInsert when text enters the text component's document, onRemove when text leaves it, and onChange when its attributes change. Requires a JTextComponent target, and follows the document the component holds across a swap.

Link copied to clipboard

Attaches a FocusListener (addFocusListener/removeFocusListener).

Runs onFocusChange whenever the component takes or loses the keyboard focus. Read isFocusOwner to tell which, or declare the two directions separately.

fun SwingModifier.focusListener(onFocusGained: (FocusEvent) -> Unit = UNDECLARED, onFocusLost: (FocusEvent) -> Unit = UNDECLARED): SwingModifier

Runs onFocusGained when the component takes the keyboard focus and onFocusLost when it loses it. A direction left undeclared reports nowhere.

Link copied to clipboard

Attaches a HierarchyListener (addHierarchyListener/removeHierarchyListener).

Runs onHierarchyChange when the component's place in the hierarchy changes - it is handed to a parent, loses one, or starts or stops being on screen. The event's change flags say which.

Link copied to clipboard

Attaches a HyperlinkListener (addHyperlinkListener/removeHyperlinkListener). Requires a JEditorPane target.

Runs onHyperlinkUpdate when the user enters, leaves or activates a link. Requires a JEditorPane target, and reports only while the pane is not editable, as hyperlinkListener describes.

Link copied to clipboard

Attaches an InternalFrameListener (addInternalFrameListener/removeInternalFrameListener). Requires a JInternalFrame target.

Runs onFrameChange on every change to the internal frame - opened, closing, closed, iconified, deiconified, activated and deactivated alike. Requires a JInternalFrame target. Declare the changes one by one to tell them apart.

fun SwingModifier.internalFrameListener(onFrameOpened: (InternalFrameEvent) -> Unit = UNDECLARED, onFrameClosing: (InternalFrameEvent) -> Unit = UNDECLARED, onFrameClosed: (InternalFrameEvent) -> Unit = UNDECLARED, onFrameIconified: (InternalFrameEvent) -> Unit = UNDECLARED, onFrameDeiconified: (InternalFrameEvent) -> Unit = UNDECLARED, onFrameActivated: (InternalFrameEvent) -> Unit = UNDECLARED, onFrameDeactivated: (InternalFrameEvent) -> Unit = UNDECLARED): SwingModifier

Runs each lambda on the change to the internal frame it is declared for. Requires a JInternalFrame target. A change left undeclared reports nowhere.

Link copied to clipboard

Attaches an ItemListener (addItemListener/removeItemListener) to a component that fires item events: AbstractButton (JCheckBox, JRadioButton, JToggleButton, JCheckBoxMenuItem, JRadioButtonMenuItem), JComboBox, and the AWT Checkbox, Choice, and List.

fun SwingModifier.itemListener(onItemStateChange: (ItemEvent) -> Unit): SwingModifier

Runs onItemStateChange on the item event of a component that fires one - the components itemListener lists, over the same event source, which reports the state a component ends up in however it got there.

inline fun <T : Component> SwingModifier.itemListener(noinline onItemStateChange: T.(ItemEvent) -> Unit): SwingModifier

Runs onItemStateChange on the item event of a component of type T that fires one, with that component as this.

fun <T : Component> SwingModifier.itemListener(targetType: KClass<T>, onItemStateChange: T.(ItemEvent) -> Unit): SwingModifier

Runs onItemStateChange on the item event of a component of type targetType that fires one, with that component as this. An event sourced anywhere else is refused; see listener.

Link copied to clipboard

Attaches a KeyListener (addKeyListener/removeKeyListener).

Runs onKeyEvent for every key event on the component - a press, a release and the character they type alike, so one keystroke reports more than once. Declare the events one by one to tell them apart.

fun SwingModifier.keyListener(onKeyTyped: (KeyEvent) -> Unit = UNDECLARED, onKeyPressed: (KeyEvent) -> Unit = UNDECLARED, onKeyReleased: (KeyEvent) -> Unit = UNDECLARED): SwingModifier

Runs each lambda on the key event it is declared for. An event left undeclared reports nowhere.

Link copied to clipboard
inline fun <T : Component, C : Any, L : Any> SwingModifier.listener(callback: C, registration: CallbackRegistration<T, C, L>): SwingModifier

Installs one library-built listener that reads the caller's callback when an event fires - the seam every builder's lambda overload is built on.

inline fun <T : Component, L : Any> SwingModifier.listener(instance: L, registration: ListenerRegistration<T, L>): SwingModifier

Installs a listener instance on the target component via the modifier mechanism - the by-identity listener seam, the one every builder taking a listener object is built on (the typed instance builders like mouseListener/actionListener and the model builders like changeListener).

fun <T : Component, C : Any, L : Any> SwingModifier.listener(targetType: KClass<T>, callback: C, registration: CallbackRegistration<T, C, L>): SwingModifier

Installs one library-built listener that reads the caller's callback, naming the target component type as a value.

fun <T : Component, L : Any> SwingModifier.listener(targetType: KClass<T>, instance: L, registration: ListenerRegistration<T, L>): SwingModifier

Installs a listener instance, naming the target component type as a value.

Link copied to clipboard

Attaches a ListSelectionListener (addListSelectionListener/removeListSelectionListener). Requires a JList target.

Runs onSelectionChange whenever the list's selection changes. Requires a JList target.

inline fun <T : JList<*>> SwingModifier.listSelectionListener(noinline onSelectionChange: T.(ListSelectionEvent) -> Unit): SwingModifier

Runs onSelectionChange on the selection event of a list of type T, with that list as this.

fun <T : JList<*>> SwingModifier.listSelectionListener(targetType: KClass<T>, onSelectionChange: T.(ListSelectionEvent) -> Unit): SwingModifier

Runs onSelectionChange on the selection event of a list of type targetType, with that list as this. An event sourced anywhere else is refused; see listener.

Link copied to clipboard

Attaches a MouseListener (addMouseListener/removeMouseListener).

Runs onMouseEvent for every mouse event on the component - a click, a press, a release, the pointer entering and the pointer leaving alike, so one interaction reports more than once. Declare the events one by one to tell them apart.

fun SwingModifier.mouseListener(onMouseClicked: (MouseEvent) -> Unit = UNDECLARED, onMousePressed: (MouseEvent) -> Unit = UNDECLARED, onMouseReleased: (MouseEvent) -> Unit = UNDECLARED, onMouseEntered: (MouseEvent) -> Unit = UNDECLARED, onMouseExited: (MouseEvent) -> Unit = UNDECLARED): SwingModifier

Runs each lambda on the mouse event it is declared for. An event left undeclared reports nowhere.

Link copied to clipboard

Attaches a MouseMotionListener (addMouseMotionListener/removeMouseMotionListener).

Runs onMouseMove whenever the pointer moves over the component, whether or not a button is held.

fun SwingModifier.mouseMotionListener(onMouseDragged: (MouseEvent) -> Unit = UNDECLARED, onMouseMoved: (MouseEvent) -> Unit = UNDECLARED): SwingModifier

Runs onMouseDragged while the pointer moves with a button held, and onMouseMoved while it moves with none. A movement left undeclared reports nowhere.

Link copied to clipboard

Attaches a MouseWheelListener (addMouseWheelListener/removeMouseWheelListener).

Runs onMouseWheel when the wheel turns over the component.

Link copied to clipboard

Attaches an unbound PropertyChangeListener (addPropertyChangeListener), notified of every bound property change. For a single property, prefer the name overload.

Runs onPropertyChange on every bound property change of the component. For a single property, prefer the name overload.

Attaches a PropertyChangeListener bound to the property name (addPropertyChangeListener(name, listener)), notified only of changes to that property.

Runs onPropertyChange on changes to the property name only.

inline fun <T : Component> SwingModifier.propertyChangeListener(name: String, noinline onPropertyChange: T.(PropertyChangeEvent) -> Unit): SwingModifier

Runs onPropertyChange on changes to the property name of a component of type T, with that component as this.

fun <T : Component> SwingModifier.propertyChangeListener(name: String, targetType: KClass<T>, onPropertyChange: T.(PropertyChangeEvent) -> Unit): SwingModifier

Runs onPropertyChange on changes to the property name of a component of type targetType, with that component as this. An event sourced anywhere else is refused; see listener.

Link copied to clipboard

Attaches a TreeExpansionListener (addTreeExpansionListener/removeTreeExpansionListener). Requires a javax.swing.JTree target.

Runs onExpansionChange whenever a node of the tree opens or closes. Requires a javax.swing.JTree target.

fun SwingModifier.treeExpansionListener(onTreeExpanded: (TreeExpansionEvent) -> Unit = UNDECLARED, onTreeCollapsed: (TreeExpansionEvent) -> Unit = UNDECLARED): SwingModifier

Runs onTreeExpanded when a node opens and onTreeCollapsed when one closes. Requires a javax.swing.JTree target. A direction left undeclared reports nowhere.

Link copied to clipboard

Attaches a TreeSelectionListener (addTreeSelectionListener/removeTreeSelectionListener). Requires a javax.swing.JTree target.

Runs onSelectionChange whenever the tree's selection changes. Requires a javax.swing.JTree target.

Link copied to clipboard

Attaches a TreeWillExpandListener (addTreeWillExpandListener/removeTreeWillExpandListener), notified before a node opens or closes. Requires a javax.swing.JTree target.

Asks onWillChange before a node of the tree opens or closes whether it may: answering false leaves the node as it was and no expansion event follows. Requires a javax.swing.JTree target.

fun SwingModifier.treeWillExpandListener(onWillExpand: (TreeExpansionEvent) -> Boolean = UNDECLARED_ANSWER, onWillCollapse: (TreeExpansionEvent) -> Boolean = UNDECLARED_ANSWER): SwingModifier

Asks onWillExpand before a node opens, and onWillCollapse before one closes, whether the change may happen: answering false leaves the node as it was and no expansion event follows. Requires a javax.swing.JTree target. A direction left undeclared allows the change.