我想将变量(== i)的值放在文本字段中,以便它的值显示在文本字段中,即从1更改为10.
def sb = new SwingBuilder()
def th = Thread.start {
for(i in 1..10) {
sleep 2000
}
}
def Pan = sb.panel(layout: new BorderLayout()) {
sb.panel(constraints: BorderLayout.NORTH){
gridLayout(cols: 2, rows: 3)
textField id:'tf', text: ?
}
}
答案 0 :(得分:0)
您可以使用doOutside
的SwingBuilder
方法执行此操作,该方法允许在EDT之外运行闭包。下面的代码执行您要执行的操作(使用表格布局而不是网格布局)。
import groovy.swing.SwingBuilder
import static javax.swing.JFrame.EXIT_ON_CLOSE
import java.awt.*
def swingBuilder = new SwingBuilder()
swingBuilder.edt {
def message
def setMessage = { String s -> message.setText(s) }
frame(title: 'Example', size: [200, 150], show: true, locationRelativeTo: null, defaultCloseOperation: EXIT_ON_CLOSE) {
borderLayout(vgap: 5)
panel(constraints: BorderLayout.CENTER, border: emptyBorder(10)) {
tableLayout(cellpadding: 5) {
tr {
td {
label 'Value' // text property is default, so it is implicit.
}
td {
message = textField(id: 'tf', columns: 5, text: '0')
}
}
}
}
}
doOutside {
for (i in 1..10) {
sleep 1000
edt { setMessage(String.valueOf(i)) }
}
}
}