Package: groovy.swing

## [Groovy] Class SwingBuilder

- groovy.swing.SwingBuilder

-     class SwingBuilder
      extends FactoryBuilderSupport

  Builder that exposes Swing components, layouts, bindings, and threading helpers through a Groovy DSL.

- - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class FactoryBuilderSupport` | `CHILD_BUILDER, CURRENT_BUILDER, CURRENT_FACTORY, CURRENT_NAME, CURRENT_NODE, OWNER, PARENT_BUILDER, PARENT_CONTEXT, PARENT_FACTORY, PARENT_NAME, PARENT_NODE, SCRIPT_CLASS_NAME, attributeDelegates, autoRegistrationComplete, autoRegistrationRunning, explicitMethods, explicitProperties, methodMissingDelegate, postInstantiateDelegates, postNodeCompletionDelegates, preInstantiateDelegates, propertyMissingDelegate, registrationGroup, registrationGroupName`

  - ### Properties Summary

    Properties
    Type | Name and description
    --- | ---
    `static String` | `DEFAULT_DELEGATE_PROPERTY_OBJECT_ID` Default attribute name used when no custom delegate property id is configured.
    `static String` | `DELEGATE_PROPERTY_OBJECT_ID` Context key containing the attribute name used to publish created nodes as builder variables.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `SwingBuilder(boolean init)` Creates a new Swing builder and optionally performs the default initialization.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `Object` | `build(Closure c)` Executes a closure against this builder for compatibility with older APIs.
    `` | `static Object` | `clientPropertyAttributeDelegate(Object builder, Object node, Object attributes)` Applies `clientProperties` and `clientProperty*` attributes to the target component.
    `` | `void` | `createKeyStrokeAction(Map attributes, JComponent component)` Binds one or more keystrokes to an action on the resolved target component.
    `` | `SwingBuilder` | `doLater(Closure c)` Schedules a closure to run on the Event Dispatch Thread using SwingUtilities.invokeLater.
    `` | `SwingBuilder` | `doOutside(Closure c)` Runs a closure outside of the Event Dispatch Thread.
    `` | `SwingBuilder` | `edt(Closure c)` Runs a closure on the Event Dispatch Thread using SwingUtilities.invokeAndWait when needed.
    `` | `static SwingBuilder` | `edtBuilder(Closure c)` Creates a new builder and runs the supplied closure on the EDT.
    `` | `static LookAndFeel` | `lookAndFeel(Object laf, Closure initCode)` Resolves and installs a look and feel with an optional initialization closure.
    `` | `static LookAndFeel` | `lookAndFeel(Map attributes, Object laf, Closure initCode)` Resolves and installs a look and feel with optional attributes and initialization logic.
    `` | `static LookAndFeel` | `lookAndFeel(Object[] lafs)` Attempts multiple look and feel candidates until one installs successfully.
    `` | `static Object` | `objectIDAttributeDelegate(Object builder, Object node, Object attributes)` Publishes created nodes into the builder variable namespace using the configured id attribute.
    `` | `Object` | `registerActionButtonWidgets()` Registers button-like widgets that can share Swing actions.
    `` | `Object` | `registerBasicLayouts()` Registers core Swing layout managers and their attribute delegates.
    `` | `Object` | `registerBasicWidgets()` Registers basic selection and value widgets.
    `` | `void` | `registerBeanFactory(String nodeName, String groupName, Class klass)` Registers a bean factory, substituting Swing-specific factory implementations for special component types.
    `` | `Object` | `registerBinding()` Registers binding-related factories and delegates.
    `` | `Object` | `registerBorders()` Registers border factories.
    `` | `Object` | `registerBoxLayout()` Registers `BoxLayout`-based containers and spacing helpers.
    `` | `Object` | `registerContainers()` Registers container widgets that can host child components.
    `` | `Object` | `registerDataModels()` Registers standard Swing data model nodes.
    `` | `Object` | `registerEditors()` Registers cell editor factories.
    `` | `Object` | `registerMDIWidgets()` Registers desktop and internal-frame widgets used for MDI applications.
    `` | `Object` | `registerMenuWidgets()` Registers menu-related widgets.
    `` | `Object` | `registerPassThruNodes()` Registers pass-through nodes that wrap existing beans or components.
    `` | `Object` | `registerRenderers()` Registers renderer factories for tables, lists, and headers.
    `` | `Object` | `registerSupportNodes()` Registers support nodes, explicit methods, and attribute delegates that do not create visible widgets.
    `` | `Object` | `registerTableComponents()` Registers tables, columns, and table model helper nodes.
    `` | `Object` | `registerTableLayout()` Registers table-layout nodes.
    `` | `Object` | `registerTextWidgets()` Registers text-oriented Swing widgets.
    `` | `Object` | `registerThreading()` Registers threading helper methods such as `edt` and `doLater`.
    `` | `Object` | `registerWindows()` Registers top-level window factories.
    `` | `KeyStroke` | `shortcut(Object key, Object modifier)` Creates a menu-shortcut keystroke for the supplied key and additional modifiers.
    `` | `KeyStroke` | `shortcut(String key, Object modifier)` Creates a menu-shortcut keystroke from a string description.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class FactoryBuilderSupport` | `addAttributeDelegate, addDisposalClosure, addPostInstantiateDelegate, addPostNodeCompletionDelegate, addPreInstantiateDelegate, autoRegisterNodes, build, build, build, checkExplicitMethod, checkValueIsNull, checkValueIsType, checkValueIsTypeNotString, createNode, dispatchNodeCall, dispathNodeCall, dispose, getAttributeDelegates, getChildBuilder, getContext, getContextAttribute, getContexts, getContinuationData, getCurrent, getCurrentBuilder, getCurrentFactory, getCurrentName, getDisposalClosures, getExplicitMethods, getExplicitProperties, getFactories, getLocalExplicitMethods, getLocalExplicitProperties, getLocalFactories, getMethodMissingDelegate, getName, getNameMappingClosure, getParentContext, getParentFactory, getParentName, getParentNode, getPostInstantiateDelegates, getPostNodeCompletionDelegates, getPreInstantiateDelegates, getProperty, getPropertyMissingDelegate, getProxyBuilder, getRegistrationGroupItems, getRegistrationGroups, getVariable, getVariables, handleNodeAttributes, invokeMethod, invokeMethod, newContext, nodeCompleted, popContext, postInstantiate, postNodeCompletion, preInstantiate, registerBeanFactory, registerBeanFactory, registerExplicitMethod, registerExplicitMethod, registerExplicitProperty, registerExplicitProperty, registerFactory, registerFactory, removeAttributeDelegate, removePostInstantiateDelegate, removePostNodeCompletionDelegate, removePreInstantiateDelegate, reset, resolveExplicitMethod, resolveExplicitProperty, resolveFactory, restoreFromContinuationData, setClosureDelegate, setMethodMissingDelegate, setNameMappingClosure, setNodeAttributes, setParent, setProperty, setPropertyMissingDelegate, setProxyBuilder, setVariable, withBuilder, withBuilder, withBuilder`
    `class Binding` | `getProperty, getVariable, getVariables, hasVariable, removeVariable, setProperty, setVariable`
    `class GroovyObjectSupport` | `getMetaClass, setMetaClass`

- - ### Property Detail

    - #### static final String DEFAULT_DELEGATE_PROPERTY_OBJECT_ID

      Default attribute name used when no custom delegate property id is configured.

    - #### static final String DELEGATE_PROPERTY_OBJECT_ID

      Context key containing the attribute name used to publish created nodes as builder variables.

  - ### Constructor Detail

    - #### SwingBuilder(boolean init)

      Creates a new Swing builder and optionally performs the default initialization.

      Parameters:
        `init` - whether superclass initialization should run immediately

  - ### Method Detail

    - #### Object build(@DelegatesTo(value=SwingBuilder)
      Closure c)

      Executes a closure against this builder for compatibility with older APIs.

      Parameters:
        `c` - the closure to execute
      Returns:
        the closure result

    - #### static Object clientPropertyAttributeDelegate(Object builder, Object node, Object attributes)

      Applies `clientProperties` and `clientProperty*` attributes to the target component.

      Parameters:
        `builder` - the active builder
        `node` - the component receiving client properties
        `attributes` - the node attributes to inspect and mutate

    - #### void createKeyStrokeAction(Map attributes, JComponent component)

      Binds one or more keystrokes to an action on the resolved target component.

      The target component is taken from the method argument, a `component:` attribute, or the current builder node. Unknown conditions default to JComponent.WHEN_FOCUSED.

      Parameters:
        `attributes` - action registration attributes
        `component` - optional explicit target component

    - #### SwingBuilder doLater(@DelegatesTo(value=SwingBuilder)
      Closure c)

      Schedules a closure to run on the Event Dispatch Thread using SwingUtilities.invokeLater.

      When running headless, the closure executes immediately.

      Parameters:
        `c` - the closure to run on the EDT
      Returns:
        this builder

    - #### SwingBuilder doOutside(@DelegatesTo(value=SwingBuilder)
      Closure c)

      Runs a closure outside of the Event Dispatch Thread.

      If called from the EDT a new thread is started immediately; otherwise the closure runs in the current thread.

      Parameters:
        `c` - the closure to run outside the EDT
      Returns:
        this builder

    - #### SwingBuilder edt(@DelegatesTo(value=SwingBuilder)
      Closure c)

      Runs a closure on the Event Dispatch Thread using SwingUtilities.invokeAndWait when needed.

      When already on the EDT, or when running headless, the closure executes immediately.

      Parameters:
        `c` - the closure to run on the EDT
      Returns:
        this builder

    - #### static SwingBuilder edtBuilder(@DelegatesTo(value=SwingBuilder)
      Closure c)

      Creates a new builder and runs the supplied closure on the EDT.

      Parameters:
        `c` - the closure to execute with the new builder
      Returns:
        the initialized builder

    - #### static LookAndFeel lookAndFeel(Object laf, Closure initCode)

      Resolves and installs a look and feel with an optional initialization closure.

      Parameters:
        `laf` - the look and feel instance, alias, or class name
        `initCode` - optional initialization closure
      Returns:
        the installed look and feel

    - #### static LookAndFeel lookAndFeel(Map attributes, Object laf, Closure initCode)

      Resolves and installs a look and feel with optional attributes and initialization logic.

      Parameters:
        `attributes` - look and feel configuration attributes
        `laf` - the look and feel instance, alias, or class name
        `initCode` - optional initialization closure
      Returns:
        the installed look and feel

    - #### static LookAndFeel lookAndFeel(Object[] lafs)

      Attempts multiple look and feel candidates until one installs successfully.

      Parameters:
        `lafs` - the look and feel candidates to try
      Returns:
        the first installed look and feel, or `null` if all candidates fail

    - #### static Object objectIDAttributeDelegate(Object builder, Object node, Object attributes)

      Publishes created nodes into the builder variable namespace using the configured id attribute.

      Parameters:
        `builder` - the active builder
        `node` - the created node
        `attributes` - the node attributes to inspect and mutate

    - #### Object registerActionButtonWidgets()

      Registers button-like widgets that can share Swing actions.

    - #### Object registerBasicLayouts()

      Registers core Swing layout managers and their attribute delegates.

    - #### Object registerBasicWidgets()

      Registers basic selection and value widgets.

    - #### void registerBeanFactory(String nodeName, String groupName, Class klass)

      Registers a bean factory, substituting Swing-specific factory implementations for special component types.

      Parameters:
        `nodeName` - the builder node name
        `groupName` - the factory group name
        `klass` - the bean class to register

    - #### Object registerBinding()

      Registers binding-related factories and delegates.

    - #### Object registerBorders()

      Registers border factories.

    - #### Object registerBoxLayout()

      Registers `BoxLayout`-based containers and spacing helpers.

    - #### Object registerContainers()

      Registers container widgets that can host child components.

    - #### Object registerDataModels()

      Registers standard Swing data model nodes.

    - #### Object registerEditors()

      Registers cell editor factories.

    - #### Object registerMDIWidgets()

      Registers desktop and internal-frame widgets used for MDI applications.

    - #### Object registerMenuWidgets()

      Registers menu-related widgets.

    - #### Object registerPassThruNodes()

      Registers pass-through nodes that wrap existing beans or components.

    - #### Object registerRenderers()

      Registers renderer factories for tables, lists, and headers.

    - #### Object registerSupportNodes()

      Registers support nodes, explicit methods, and attribute delegates that do not create visible widgets.

    - #### Object registerTableComponents()

      Registers tables, columns, and table model helper nodes.

    - #### Object registerTableLayout()

      Registers table-layout nodes.

    - #### Object registerTextWidgets()

      Registers text-oriented Swing widgets.

    - #### Object registerThreading()

      Registers threading helper methods such as `edt` and `doLater`.

    - #### Object registerWindows()

      Registers top-level window factories.

    - #### KeyStroke shortcut(Object key, Object modifier)

      Creates a menu-shortcut keystroke for the supplied key and additional modifiers.

      Parameters:
        `key` - the key specification accepted by KeyStroke.getKeyStroke
        `modifier` - additional modifier mask bits
      Returns:
        the created keystroke

    - #### KeyStroke shortcut(String key, Object modifier)

      Creates a menu-shortcut keystroke from a string description.

      Parameters:
        `key` - the keystroke description
        `modifier` - additional modifier mask bits
      Returns:
        the created keystroke, or `null` if the description cannot be parsed