-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathStandardColoursEx.kt
115 lines (95 loc) · 3.28 KB
/
StandardColoursEx.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.zetcode
import java.awt.Color
import java.awt.Dimension
import java.awt.EventQueue
import javax.swing.GroupLayout
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.SwingConstants.LEADING
class StandardColoursEx(title: String) : JFrame() {
init {
createUI(title)
}
private fun createUI(title: String) {
val stdCols = arrayOf<Color>(
Color.black, Color.blue, Color.cyan,
Color.darkGray, Color.gray, Color.green, Color.lightGray, Color.magenta,
Color.orange, Color.pink, Color.red, Color.white, Color.yellow
)
val labels = stdCols.map {
JLabel("", null, LEADING).apply {
minimumSize = Dimension(90, 40)
background = it
isOpaque = true
}
}
createLayout(labels)
setTitle(title)
defaultCloseOperation = EXIT_ON_CLOSE
setLocationRelativeTo(null)
}
private fun createLayout(labels: List<JLabel>) {
val gl = GroupLayout(contentPane)
contentPane.layout = gl
gl.autoCreateContainerGaps = true
gl.autoCreateGaps = true
gl.setHorizontalGroup(
gl.createParallelGroup()
.addGroup(
gl.createSequentialGroup()
.addComponent(labels[0])
.addComponent(labels[1])
.addComponent(labels[2])
.addComponent(labels[3])
)
.addGroup(
gl.createSequentialGroup()
.addComponent(labels[4])
.addComponent(labels[5])
.addComponent(labels[6])
.addComponent(labels[7])
)
.addGroup(
gl.createSequentialGroup()
.addComponent(labels[8])
.addComponent(labels[9])
.addComponent(labels[10])
.addComponent(labels[11])
)
.addComponent(labels[12])
)
gl.setVerticalGroup(
gl.createSequentialGroup()
.addGroup(
gl.createParallelGroup()
.addComponent(labels[0])
.addComponent(labels[1])
.addComponent(labels[2])
.addComponent(labels[3])
)
.addGroup(
gl.createParallelGroup()
.addComponent(labels[4])
.addComponent(labels[5])
.addComponent(labels[6])
.addComponent(labels[7])
)
.addGroup(
gl.createParallelGroup()
.addComponent(labels[8])
.addComponent(labels[9])
.addComponent(labels[10])
.addComponent(labels[11])
)
.addComponent(labels[12])
)
pack()
}
}
private fun createAndShowGUI() {
val frame = StandardColoursEx("Standard colours")
frame.isVisible = true
}
fun main() {
EventQueue.invokeLater(::createAndShowGUI)
}