CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-codehaus-groovy--groovy-swing

A declarative Swing GUI builder for Groovy applications that provides a concise and maintainable way to create complex Swing user interfaces

Pending
Overview
Eval results
Files

extensions.mddocs/

Swing Extensions

Groovy-specific enhancements to standard Swing components providing operator overloads and convenient methods for more idiomatic Groovy code.

Capabilities

Container Extensions

Enhanced methods for Swing containers providing collection-like operations.

/**
 * Collection-like operations for Container components
 */
class ContainerExtensions {
    /** Get the number of components in the container */
    static int size(Container self)
    
    /** Get component at specified index */
    static Component getAt(Container self, int index)
    
    /** Add component using left-shift operator */
    static Container leftShift(Container self, Component component)
    
    /** Iterate over components */
    static Iterator<Component> iterator(Container self)
    
    /** Remove all components */
    static void clear(Container self)
}

ButtonGroup Extensions

Collection-like operations for ButtonGroup.

/**
 * Collection-like operations for ButtonGroup
 */
class ButtonGroupExtensions {
    /** Get the number of buttons in the group */
    static int size(ButtonGroup self)
    
    /** Get button at specified index */
    static AbstractButton getAt(ButtonGroup self, int index)
    
    /** Add button using left-shift operator */
    static ButtonGroup leftShift(ButtonGroup self, AbstractButton button)
    
    /** Iterate over buttons */
    static Iterator<AbstractButton> iterator(ButtonGroup self)
}

List Model Extensions

Enhanced methods for list models and combo boxes.

/**
 * Collection-like operations for ListModel
 */
class ListModelExtensions {
    /** Get the size of the list model */
    static int size(ListModel self)
    
    /** Get element at specified index */
    static Object getAt(ListModel self, int index)
    
    /** Iterate over elements */
    static Iterator iterator(ListModel self)
}

/**
 * Mutable operations for DefaultListModel
 */
class DefaultListModelExtensions {
    /** Add element using left-shift operator */
    static DefaultListModel leftShift(DefaultListModel self, Object element)
    
    /** Set element at specified index */
    static void putAt(DefaultListModel self, int index, Object element)
    
    /** Remove all elements */
    static void clear(DefaultListModel self)
}

ComboBox Extensions

Collection-like operations for JComboBox.

/**
 * Collection-like operations for JComboBox
 */
class JComboBoxExtensions {
    /** Get the number of items */
    static int size(JComboBox self)
    
    /** Get item at specified index */
    static Object getAt(JComboBox self, int index)
    
    /** Add item using left-shift operator */
    static JComboBox leftShift(JComboBox self, Object item)
    
    /** Remove all items */
    static void clear(JComboBox self)
    
    /** Iterate over items */
    static Iterator iterator(JComboBox self)
}

Table Model Extensions

Enhanced methods for table models and operations.

/**
 * Collection-like operations for TableModel
 */
class TableModelExtensions {
    /** Get the number of rows */
    static int size(TableModel self)
    
    /** Get row at specified index as array */
    static Object[] getAt(TableModel self, int index)
    
    /** Iterate over rows */
    static Iterator iterator(TableModel self)
}

/**
 * Mutable operations for DefaultTableModel  
 */
class DefaultTableModelExtensions {
    /** Add row using left-shift operator */
    static DefaultTableModel leftShift(DefaultTableModel self, Object[] row)
    
    /** Add row using left-shift operator */
    static DefaultTableModel leftShift(DefaultTableModel self, Vector row)
    
    /** Iterate over rows */
    static Iterator iterator(DefaultTableModel self)
}

Tree Extensions

Enhanced methods for tree components and models.

/**
 * Collection-like operations for TreePath
 */
class TreePathExtensions {
    /** Get the path length */
    static int size(TreePath self)
    
    /** Get path component at specified index */
    static Object getAt(TreePath self, int index)
    
    /** Append object to path using left-shift operator */
    static TreePath leftShift(TreePath self, Object object)
    
    /** Iterate over path components */
    static Iterator iterator(TreePath self)
}

/**
 * Collection-like operations for TreeNode
 */
class TreeNodeExtensions {
    /** Get the number of children */  
    static int size(TreeNode self)
    
    /** Get child at specified index */
    static TreeNode getAt(TreeNode self, int index)
    
    /** Iterate over children */
    static Iterator<TreeNode> iterator(TreeNode self)
}

/**
 * Mutable operations for MutableTreeNode
 */
class MutableTreeNodeExtensions {
    /** Add child using left-shift operator */
    static MutableTreeNode leftShift(MutableTreeNode self, MutableTreeNode node)
    
    /** Set child at specified index */
    static void putAt(MutableTreeNode self, int index, MutableTreeNode node)
}

Menu Extensions

Collection-like operations for JMenu components.

/**
 * Collection-like operations for JMenu
 */
class JMenuExtensions {
    /** Get the number of menu items */
    static int size(JMenu self)
    
    /** Get menu item at specified index */
    static Component getAt(JMenu self, int index)
    
    /** Add menu item using left-shift operator */
    static JMenu leftShift(JMenu self, JMenuItem item)
    
    /** Add menu using left-shift operator */
    static JMenu leftShift(JMenu self, JMenu menu)
    
    /** Add component using left-shift operator */
    static JMenu leftShift(JMenu self, Component component)
    
    /** Add action using left-shift operator */
    static JMenu leftShift(JMenu self, Action action)
    
    /** Iterate over menu components */
    static Iterator<Component> iterator(JMenu self)
}

TabbedPane Extensions

Enhanced methods for JTabbedPane.

/**
 * Collection-like operations for JTabbedPane
 */
class JTabbedPaneExtensions {
    /** Get the number of tabs */
    static int size(JTabbedPane self)
    
    /** Get tab component at specified index */
    static Component getAt(JTabbedPane self, int index)
    
    /** Remove all tabs */
    static void clear(JTabbedPane self)
    
    /** Iterate over tab components */
    static Iterator<Component> iterator(JTabbedPane self)
}

Button Extensions

Enhanced mnemonic support for buttons.

/**
 * Enhanced button operations
 */
class AbstractButtonExtensions {
    /** Set mnemonic from single character string */
    static void setMnemonic(AbstractButton self, String mnemonic)
}

Usage Examples

Container Operations

import groovy.swing.SwingBuilder
import javax.swing.*

def swing = new SwingBuilder()
def panel = swing.panel()

// Use collection-like operations
panel << swing.button(text: 'Button 1')
panel << swing.button(text: 'Button 2')
panel << swing.button(text: 'Button 3')

println "Panel has ${panel.size()} components"

// Iterate over components
panel.each { component ->
    println "Component: ${component.class.simpleName}"
}

// Access by index
def firstButton = panel[0]

List Model Operations

def listModel = new DefaultListModel()

// Add items using left-shift
listModel << 'Item 1'
listModel << 'Item 2' 
listModel << 'Item 3'

// Access and modify
listModel[1] = 'Modified Item 2'

// Iterate
listModel.each { item ->
    println "Item: $item"
}

println "List has ${listModel.size()} items"

ComboBox Operations

def comboBox = swing.comboBox()

// Add items using left-shift
comboBox << 'Option A'
comboBox << 'Option B'
comboBox << 'Option C'

// Access by index
def firstOption = comboBox[0]

// Clear all items
comboBox.clear()

Button Mnemonic

def button = swing.button(text: 'Save File')

// Set mnemonic using single character
button.mnemonic = 'S'  // Equivalent to button.setMnemonic('S')

Install with Tessl CLI

npx tessl i tessl/maven-org-codehaus-groovy--groovy-swing

docs

data-binding.md

extensions.md

gui-building.md

index.md

layout-management.md

look-and-feel.md

models.md

tile.json