/
App.kt
69 lines (61 loc) · 1.86 KB
/
App.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
package example
import java.awt.*
import javax.swing.*
fun makeUI(): Component {
val log = JTextArea()
info(log, "FileChooser.newFolderActionLabelText")
info(log, "FileChooser.newFolderToolTipText")
info(log, "FileChooser.newFolderAccessibleName")
info(log, "FileChooser.other.newFolder")
info(log, "FileChooser.other.newFolder.subsequent")
val newFolderKey = "FileChooser.win32.newFolder"
val subsequentKey = "FileChooser.win32.newFolder.subsequent"
info(log, newFolderKey)
info(log, subsequentKey)
UIManager.put(newFolderKey, "新しいフォルダー")
UIManager.put(subsequentKey, "新しいフォルダー ({0})")
info(log, newFolderKey)
info(log, subsequentKey)
val button = JButton("show JFileChooser")
button.addActionListener {
val fileChooser = JFileChooser()
val retValue = fileChooser.showOpenDialog(log.rootPane)
if (retValue == JFileChooser.APPROVE_OPTION) {
log.append(fileChooser.selectedFile.absolutePath + "\n")
}
}
val box = Box.createHorizontalBox().also {
it.border = BorderFactory.createTitledBorder("JFileChooser")
it.add(Box.createHorizontalGlue())
it.add(button)
it.add(Box.createHorizontalGlue())
}
return JPanel(BorderLayout()).also {
it.add(box, BorderLayout.NORTH)
it.add(JScrollPane(log))
it.preferredSize = Dimension(320, 240)
}
}
private fun info(
log: JTextArea,
key: String,
) {
log.append("%s:%n %s%n".format(key, UIManager.getString(key)))
}
fun main() {
EventQueue.invokeLater {
runCatching {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
}.onFailure {
it.printStackTrace()
Toolkit.getDefaultToolkit().beep()
}
JFrame().apply {
defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
contentPane.add(makeUI())
pack()
setLocationRelativeTo(null)
isVisible = true
}
}
}