CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-groovy--groovy-swing

SwingBuilder for creating Swing GUIs in Groovy - provides DSL for declarative UI construction

Pending
Overview
Eval results
Files

borders.mddocs/

Borders and Styling

Groovy Swing provides factory methods for creating all major Swing border types, enabling declarative visual styling of components.

Basic Border Types

Standard Swing borders for component styling.

// Line borders
def lineBorder(Map attributes = [:])

// Bevel borders  
def raisedBevelBorder(Map attributes = [:])
def loweredBevelBorder(Map attributes = [:])

// Etched borders
def etchedBorder(Map attributes = [:])
def raisedEtchedBorder(Map attributes = [:])
def loweredEtchedBorder(Map attributes = [:])

// Titled borders
def titledBorder(Map attributes = [:])

// Empty borders (spacing)
def emptyBorder(Map attributes = [:])

// Matte borders
def matteBorder(Map attributes = [:])

// Compound borders
def compoundBorder(Map attributes = [:])

Line Borders

Simple line borders with customizable color and thickness.

def lineBorder(Map attributes = [:])

// LineBorder attributes:
// color: Color - border color (default: Color.BLACK)
// thickness: int - border thickness in pixels (default: 1)
// roundedCorners: boolean - whether corners are rounded (default: false)

Line Border Examples

// Basic line border
swing.panel(border: lineBorder()) {
    label(text: 'Basic line border')
}

// Colored line border
swing.panel(border: lineBorder(color: Color.RED, thickness: 2)) {
    label(text: 'Red line border')
}

// Rounded line border
swing.panel(border: lineBorder(color: Color.BLUE, thickness: 3, roundedCorners: true)) {
    label(text: 'Rounded blue border')
}

Bevel Borders

3D bevel effect borders for raised or lowered appearance.

def raisedBevelBorder(Map attributes = [:])
def loweredBevelBorder(Map attributes = [:])

// BevelBorder attributes:
// highlightOuter: Color - outer highlight color
// highlightInner: Color - inner highlight color
// shadowOuter: Color - outer shadow color
// shadowInner: Color - inner shadow color

Bevel Border Examples

// Standard raised bevel
swing.panel(border: raisedBevelBorder()) {
    label(text: 'Raised appearance')
}

// Standard lowered bevel
swing.panel(border: loweredBevelBorder()) {
    label(text: 'Lowered appearance')
}

// Custom colored bevel
swing.panel(border: raisedBevelBorder(
    highlightOuter: Color.WHITE,
    highlightInner: Color.LIGHT_GRAY,
    shadowOuter: Color.DARK_GRAY,
    shadowInner: Color.BLACK
)) {
    label(text: 'Custom bevel colors')
}

Etched Borders

Etched effect borders for subtle 3D appearance.

def etchedBorder(Map attributes = [:])
def raisedEtchedBorder(Map attributes = [:])
def loweredEtchedBorder(Map attributes = [:])

// EtchedBorder attributes:
// etchType: int - RAISED or LOWERED (default: LOWERED)
// highlight: Color - highlight color
// shadow: Color - shadow color

Etched Border Examples

// Default etched border (lowered)
swing.panel(border: etchedBorder()) {
    label(text: 'Default etched')
}

// Raised etched border
swing.panel(border: raisedEtchedBorder()) {
    label(text: 'Raised etched')
}

// Custom etched colors
swing.panel(border: etchedBorder(
    highlight: Color.YELLOW,
    shadow: Color.ORANGE
)) {
    label(text: 'Custom etched colors')
}

Titled Borders

Borders with text titles for grouping and labeling.

def titledBorder(Map attributes = [:])

// TitledBorder attributes:
// title: String - border title text
// border: Border - underlying border (optional)
// position: int - title position (TOP, BOTTOM, etc.)
// justification: int - title justification (LEFT, CENTER, RIGHT)
// font: Font - title font
// color: Color - title color

Titled Border Examples

// Basic titled border
swing.panel(border: titledBorder(title: 'Settings')) {
    checkBox(text: 'Enable feature')
    checkBox(text: 'Auto-save')
}

// Titled border with custom positioning
swing.panel(border: titledBorder(
    title: 'Advanced Options',
    position: TitledBorder.BOTTOM,
    justification: TitledBorder.RIGHT
)) {
    slider(minimum: 0, maximum: 100)
}

// Titled border with custom styling
swing.panel(border: titledBorder(
    title: 'User Information',
    font: new Font('Arial', Font.BOLD, 14),
    color: Color.BLUE,
    border: lineBorder(color: Color.GRAY)
)) {
    textField(columns: 20)
    textField(columns: 20)
}

// Nested titled borders
swing.panel(border: titledBorder(title: 'Outer Group')) {
    panel(border: titledBorder(title: 'Inner Group')) {
        button(text: 'Action')
    }
}

Empty Borders

Invisible borders that provide spacing around components.

def emptyBorder(Map attributes = [:])

// EmptyBorder attributes:
// top: int - top margin in pixels
// left: int - left margin in pixels  
// bottom: int - bottom margin in pixels
// right: int - right margin in pixels
// insets: Insets - margin insets object

Empty Border Examples

// Uniform spacing
swing.panel(border: emptyBorder(top: 10, left: 10, bottom: 10, right: 10)) {
    label(text: '10px padding on all sides')
}

// Different spacing per side
swing.panel(border: emptyBorder(top: 5, left: 15, bottom: 5, right: 15)) {
    label(text: 'Horizontal padding larger than vertical')
}

// Using Insets object
swing.panel(border: emptyBorder(insets: new Insets(20, 20, 20, 20))) {
    label(text: '20px padding via Insets')
}

Matte Borders

Solid color borders with customizable thickness per side.

def matteBorder(Map attributes = [:])

// MatteBorder attributes:
// top: int - top border thickness
// left: int - left border thickness
// bottom: int - bottom border thickness  
// right: int - right border thickness
// color: Color - border color
// icon: Icon - border icon (for textured borders)

Matte Border Examples

// Uniform matte border
swing.panel(border: matteBorder(
    top: 2, left: 2, bottom: 2, right: 2,
    color: Color.GREEN
)) {
    label(text: 'Green matte border')
}

// Asymmetric matte border
swing.panel(border: matteBorder(
    top: 1, left: 5, bottom: 1, right: 5,
    color: Color.RED
)) {
    label(text: 'Thick left/right borders')
}

// Textured matte border with icon
swing.panel(border: matteBorder(
    top: 10, left: 10, bottom: 10, right: 10,
    icon: imageIcon('/textures/wood.png')
)) {
    label(text: 'Textured border')
}

Compound Borders

Composite borders that combine multiple border types.

def compoundBorder(Map attributes = [:])

// CompoundBorder attributes:
// outside: Border - outer border
// inside: Border - inner border

Compound Border Examples

// Line border with padding
swing.panel(border: compoundBorder(
    outside: lineBorder(color: Color.BLACK),
    inside: emptyBorder(top: 10, left: 10, bottom: 10, right: 10)
)) {
    label(text: 'Line border with padding')
}

// Titled border with bevel effect
swing.panel(border: compoundBorder(
    outside: titledBorder(title: 'Panel Title'),
    inside: loweredBevelBorder()
)) {
    textArea(rows: 5, columns: 30)
}

// Complex multi-layer border
swing.panel(border: compoundBorder(
    outside: compoundBorder(
        outside: lineBorder(color: Color.DARK_GRAY, thickness: 2),
        inside: emptyBorder(top: 5, left: 5, bottom: 5, right: 5)
    ),
    inside: compoundBorder(
        outside: raisedBevelBorder(),
        inside: emptyBorder(top: 10, left: 10, bottom: 10, right: 10)
    )
)) {
    label(text: 'Multi-layer border effect')
}

Border Usage Patterns

Form Sections

swing.frame(title: 'Form with Borders') {
    vbox {
        // Personal information section
        panel(border: titledBorder(title: 'Personal Information')) {
            gridBagLayout()
            label(text: 'Name:', constraints: gbc(gridx: 0, gridy: 0))
            textField(constraints: gbc(gridx: 1, gridy: 0, fill: GridBagConstraints.HORIZONTAL))
            
            label(text: 'Email:', constraints: gbc(gridx: 0, gridy: 1))
            textField(constraints: gbc(gridx: 1, gridy: 1, fill: GridBagConstraints.HORIZONTAL))
        }
        
        vstrut(height: 10)
        
        // Preferences section  
        panel(border: titledBorder(title: 'Preferences')) {
            vbox {
                checkBox(text: 'Enable notifications')
                checkBox(text: 'Auto-save documents')
                checkBox(text: 'Show advanced options')
            }
        }
        
        vstrut(height: 10)
        
        // Action buttons with border
        panel(border: compoundBorder(
            outside: etchedBorder(),
            inside: emptyBorder(top: 10, left: 10, bottom: 10, right: 10)
        )) {
            hbox {
                hglue()
                button(text: 'Cancel')
                hstrut(width: 10)
                button(text: 'Save')
            }
        }
    }
}

Status Panels

// Status indicators with colored borders
swing.panel {
    hbox {
        // Success status
        panel(border: compoundBorder(
            outside: lineBorder(color: Color.GREEN, thickness: 2),
            inside: emptyBorder(top: 5, left: 10, bottom: 5, right: 10)
        )) {
            label(text: 'Connected', foreground: Color.GREEN)
        }
        
        hstrut(width: 10)
        
        // Warning status
        panel(border: compoundBorder(
            outside: lineBorder(color: Color.ORANGE, thickness: 2),
            inside: emptyBorder(top: 5, left: 10, bottom: 5, right: 10)
        )) {
            label(text: 'Warning', foreground: Color.ORANGE)
        }
        
        hstrut(width: 10)
        
        // Error status
        panel(border: compoundBorder(
            outside: lineBorder(color: Color.RED, thickness: 2),
            inside: emptyBorder(top: 5, left: 10, bottom: 5, right: 10)
        )) {
            label(text: 'Disconnected', foreground: Color.RED)
        }
    }
}

Dynamic Border Changes

def panel = swing.panel(border: lineBorder()) {
    label(text: 'Dynamic border example')
}

// Change border based on state
def updateBorderForState = { state ->
    switch(state) {
        case 'normal':
            panel.border = swing.lineBorder()
            break
        case 'selected':
            panel.border = swing.compoundBorder(
                outside: swing.lineBorder(color: Color.BLUE, thickness: 2),
                inside: swing.emptyBorder(top: 2, left: 2, bottom: 2, right: 2)
            )
            break
        case 'error':
            panel.border = swing.lineBorder(color: Color.RED, thickness: 2)
            break
    }
    panel.repaint()
}

Install with Tessl CLI

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

docs

borders.md

components.md

core-builder.md

data-binding.md

index.md

layouts.md

menus.md

tables.md

tile.json