0
# Borders and Styling
1
2
Groovy Swing provides factory methods for creating all major Swing border types, enabling declarative visual styling of components.
3
4
## Basic Border Types
5
6
Standard Swing borders for component styling.
7
8
```groovy { .api }
9
// Line borders
10
def lineBorder(Map attributes = [:])
11
12
// Bevel borders
13
def raisedBevelBorder(Map attributes = [:])
14
def loweredBevelBorder(Map attributes = [:])
15
16
// Etched borders
17
def etchedBorder(Map attributes = [:])
18
def raisedEtchedBorder(Map attributes = [:])
19
def loweredEtchedBorder(Map attributes = [:])
20
21
// Titled borders
22
def titledBorder(Map attributes = [:])
23
24
// Empty borders (spacing)
25
def emptyBorder(Map attributes = [:])
26
27
// Matte borders
28
def matteBorder(Map attributes = [:])
29
30
// Compound borders
31
def compoundBorder(Map attributes = [:])
32
```
33
34
## Line Borders
35
36
Simple line borders with customizable color and thickness.
37
38
```groovy { .api }
39
def lineBorder(Map attributes = [:])
40
41
// LineBorder attributes:
42
// color: Color - border color (default: Color.BLACK)
43
// thickness: int - border thickness in pixels (default: 1)
44
// roundedCorners: boolean - whether corners are rounded (default: false)
45
```
46
47
### Line Border Examples
48
49
```groovy
50
// Basic line border
51
swing.panel(border: lineBorder()) {
52
label(text: 'Basic line border')
53
}
54
55
// Colored line border
56
swing.panel(border: lineBorder(color: Color.RED, thickness: 2)) {
57
label(text: 'Red line border')
58
}
59
60
// Rounded line border
61
swing.panel(border: lineBorder(color: Color.BLUE, thickness: 3, roundedCorners: true)) {
62
label(text: 'Rounded blue border')
63
}
64
```
65
66
## Bevel Borders
67
68
3D bevel effect borders for raised or lowered appearance.
69
70
```groovy { .api }
71
def raisedBevelBorder(Map attributes = [:])
72
def loweredBevelBorder(Map attributes = [:])
73
74
// BevelBorder attributes:
75
// highlightOuter: Color - outer highlight color
76
// highlightInner: Color - inner highlight color
77
// shadowOuter: Color - outer shadow color
78
// shadowInner: Color - inner shadow color
79
```
80
81
### Bevel Border Examples
82
83
```groovy
84
// Standard raised bevel
85
swing.panel(border: raisedBevelBorder()) {
86
label(text: 'Raised appearance')
87
}
88
89
// Standard lowered bevel
90
swing.panel(border: loweredBevelBorder()) {
91
label(text: 'Lowered appearance')
92
}
93
94
// Custom colored bevel
95
swing.panel(border: raisedBevelBorder(
96
highlightOuter: Color.WHITE,
97
highlightInner: Color.LIGHT_GRAY,
98
shadowOuter: Color.DARK_GRAY,
99
shadowInner: Color.BLACK
100
)) {
101
label(text: 'Custom bevel colors')
102
}
103
```
104
105
## Etched Borders
106
107
Etched effect borders for subtle 3D appearance.
108
109
```groovy { .api }
110
def etchedBorder(Map attributes = [:])
111
def raisedEtchedBorder(Map attributes = [:])
112
def loweredEtchedBorder(Map attributes = [:])
113
114
// EtchedBorder attributes:
115
// etchType: int - RAISED or LOWERED (default: LOWERED)
116
// highlight: Color - highlight color
117
// shadow: Color - shadow color
118
```
119
120
### Etched Border Examples
121
122
```groovy
123
// Default etched border (lowered)
124
swing.panel(border: etchedBorder()) {
125
label(text: 'Default etched')
126
}
127
128
// Raised etched border
129
swing.panel(border: raisedEtchedBorder()) {
130
label(text: 'Raised etched')
131
}
132
133
// Custom etched colors
134
swing.panel(border: etchedBorder(
135
highlight: Color.YELLOW,
136
shadow: Color.ORANGE
137
)) {
138
label(text: 'Custom etched colors')
139
}
140
```
141
142
## Titled Borders
143
144
Borders with text titles for grouping and labeling.
145
146
```groovy { .api }
147
def titledBorder(Map attributes = [:])
148
149
// TitledBorder attributes:
150
// title: String - border title text
151
// border: Border - underlying border (optional)
152
// position: int - title position (TOP, BOTTOM, etc.)
153
// justification: int - title justification (LEFT, CENTER, RIGHT)
154
// font: Font - title font
155
// color: Color - title color
156
```
157
158
### Titled Border Examples
159
160
```groovy
161
// Basic titled border
162
swing.panel(border: titledBorder(title: 'Settings')) {
163
checkBox(text: 'Enable feature')
164
checkBox(text: 'Auto-save')
165
}
166
167
// Titled border with custom positioning
168
swing.panel(border: titledBorder(
169
title: 'Advanced Options',
170
position: TitledBorder.BOTTOM,
171
justification: TitledBorder.RIGHT
172
)) {
173
slider(minimum: 0, maximum: 100)
174
}
175
176
// Titled border with custom styling
177
swing.panel(border: titledBorder(
178
title: 'User Information',
179
font: new Font('Arial', Font.BOLD, 14),
180
color: Color.BLUE,
181
border: lineBorder(color: Color.GRAY)
182
)) {
183
textField(columns: 20)
184
textField(columns: 20)
185
}
186
187
// Nested titled borders
188
swing.panel(border: titledBorder(title: 'Outer Group')) {
189
panel(border: titledBorder(title: 'Inner Group')) {
190
button(text: 'Action')
191
}
192
}
193
```
194
195
## Empty Borders
196
197
Invisible borders that provide spacing around components.
198
199
```groovy { .api }
200
def emptyBorder(Map attributes = [:])
201
202
// EmptyBorder attributes:
203
// top: int - top margin in pixels
204
// left: int - left margin in pixels
205
// bottom: int - bottom margin in pixels
206
// right: int - right margin in pixels
207
// insets: Insets - margin insets object
208
```
209
210
### Empty Border Examples
211
212
```groovy
213
// Uniform spacing
214
swing.panel(border: emptyBorder(top: 10, left: 10, bottom: 10, right: 10)) {
215
label(text: '10px padding on all sides')
216
}
217
218
// Different spacing per side
219
swing.panel(border: emptyBorder(top: 5, left: 15, bottom: 5, right: 15)) {
220
label(text: 'Horizontal padding larger than vertical')
221
}
222
223
// Using Insets object
224
swing.panel(border: emptyBorder(insets: new Insets(20, 20, 20, 20))) {
225
label(text: '20px padding via Insets')
226
}
227
```
228
229
## Matte Borders
230
231
Solid color borders with customizable thickness per side.
232
233
```groovy { .api }
234
def matteBorder(Map attributes = [:])
235
236
// MatteBorder attributes:
237
// top: int - top border thickness
238
// left: int - left border thickness
239
// bottom: int - bottom border thickness
240
// right: int - right border thickness
241
// color: Color - border color
242
// icon: Icon - border icon (for textured borders)
243
```
244
245
### Matte Border Examples
246
247
```groovy
248
// Uniform matte border
249
swing.panel(border: matteBorder(
250
top: 2, left: 2, bottom: 2, right: 2,
251
color: Color.GREEN
252
)) {
253
label(text: 'Green matte border')
254
}
255
256
// Asymmetric matte border
257
swing.panel(border: matteBorder(
258
top: 1, left: 5, bottom: 1, right: 5,
259
color: Color.RED
260
)) {
261
label(text: 'Thick left/right borders')
262
}
263
264
// Textured matte border with icon
265
swing.panel(border: matteBorder(
266
top: 10, left: 10, bottom: 10, right: 10,
267
icon: imageIcon('/textures/wood.png')
268
)) {
269
label(text: 'Textured border')
270
}
271
```
272
273
## Compound Borders
274
275
Composite borders that combine multiple border types.
276
277
```groovy { .api }
278
def compoundBorder(Map attributes = [:])
279
280
// CompoundBorder attributes:
281
// outside: Border - outer border
282
// inside: Border - inner border
283
```
284
285
### Compound Border Examples
286
287
```groovy
288
// Line border with padding
289
swing.panel(border: compoundBorder(
290
outside: lineBorder(color: Color.BLACK),
291
inside: emptyBorder(top: 10, left: 10, bottom: 10, right: 10)
292
)) {
293
label(text: 'Line border with padding')
294
}
295
296
// Titled border with bevel effect
297
swing.panel(border: compoundBorder(
298
outside: titledBorder(title: 'Panel Title'),
299
inside: loweredBevelBorder()
300
)) {
301
textArea(rows: 5, columns: 30)
302
}
303
304
// Complex multi-layer border
305
swing.panel(border: compoundBorder(
306
outside: compoundBorder(
307
outside: lineBorder(color: Color.DARK_GRAY, thickness: 2),
308
inside: emptyBorder(top: 5, left: 5, bottom: 5, right: 5)
309
),
310
inside: compoundBorder(
311
outside: raisedBevelBorder(),
312
inside: emptyBorder(top: 10, left: 10, bottom: 10, right: 10)
313
)
314
)) {
315
label(text: 'Multi-layer border effect')
316
}
317
```
318
319
## Border Usage Patterns
320
321
### Form Sections
322
323
```groovy
324
swing.frame(title: 'Form with Borders') {
325
vbox {
326
// Personal information section
327
panel(border: titledBorder(title: 'Personal Information')) {
328
gridBagLayout()
329
label(text: 'Name:', constraints: gbc(gridx: 0, gridy: 0))
330
textField(constraints: gbc(gridx: 1, gridy: 0, fill: GridBagConstraints.HORIZONTAL))
331
332
label(text: 'Email:', constraints: gbc(gridx: 0, gridy: 1))
333
textField(constraints: gbc(gridx: 1, gridy: 1, fill: GridBagConstraints.HORIZONTAL))
334
}
335
336
vstrut(height: 10)
337
338
// Preferences section
339
panel(border: titledBorder(title: 'Preferences')) {
340
vbox {
341
checkBox(text: 'Enable notifications')
342
checkBox(text: 'Auto-save documents')
343
checkBox(text: 'Show advanced options')
344
}
345
}
346
347
vstrut(height: 10)
348
349
// Action buttons with border
350
panel(border: compoundBorder(
351
outside: etchedBorder(),
352
inside: emptyBorder(top: 10, left: 10, bottom: 10, right: 10)
353
)) {
354
hbox {
355
hglue()
356
button(text: 'Cancel')
357
hstrut(width: 10)
358
button(text: 'Save')
359
}
360
}
361
}
362
}
363
```
364
365
### Status Panels
366
367
```groovy
368
// Status indicators with colored borders
369
swing.panel {
370
hbox {
371
// Success status
372
panel(border: compoundBorder(
373
outside: lineBorder(color: Color.GREEN, thickness: 2),
374
inside: emptyBorder(top: 5, left: 10, bottom: 5, right: 10)
375
)) {
376
label(text: 'Connected', foreground: Color.GREEN)
377
}
378
379
hstrut(width: 10)
380
381
// Warning status
382
panel(border: compoundBorder(
383
outside: lineBorder(color: Color.ORANGE, thickness: 2),
384
inside: emptyBorder(top: 5, left: 10, bottom: 5, right: 10)
385
)) {
386
label(text: 'Warning', foreground: Color.ORANGE)
387
}
388
389
hstrut(width: 10)
390
391
// Error status
392
panel(border: compoundBorder(
393
outside: lineBorder(color: Color.RED, thickness: 2),
394
inside: emptyBorder(top: 5, left: 10, bottom: 5, right: 10)
395
)) {
396
label(text: 'Disconnected', foreground: Color.RED)
397
}
398
}
399
}
400
```
401
402
### Dynamic Border Changes
403
404
```groovy
405
def panel = swing.panel(border: lineBorder()) {
406
label(text: 'Dynamic border example')
407
}
408
409
// Change border based on state
410
def updateBorderForState = { state ->
411
switch(state) {
412
case 'normal':
413
panel.border = swing.lineBorder()
414
break
415
case 'selected':
416
panel.border = swing.compoundBorder(
417
outside: swing.lineBorder(color: Color.BLUE, thickness: 2),
418
inside: swing.emptyBorder(top: 2, left: 2, bottom: 2, right: 2)
419
)
420
break
421
case 'error':
422
panel.border = swing.lineBorder(color: Color.RED, thickness: 2)
423
break
424
}
425
panel.repaint()
426
}
427
```