从Groovy SwingBuilder

时间:2017-05-26 12:50:26

标签: groovy swingbuilder

假设我使用SwingBuilder声明一个对象,如下所示:

swing.button(id:'something')

我知道我可以通过调用:

从SwingBuilder获取Component

swing."something"

但是,如何将Component返回的实例作为字符串转到其id

Component c = getMyButton()
String whatIWant = c.id    //Property doesn't exist
String attempt2  = c['id'] //Property doesn't exist

1 个答案:

答案 0 :(得分:1)

我相信你要找的是名称,所以Component#getName()应该做你想做的事。

例如:

some_secret_internal_function_or_method_of_dygraphs()

不幸的是,这没有记录,但是it appears to be what the Groovy SwingBuilder source does虽然perhaps only when there is no explicit .id propertyComponent c = getMyButton() String whatIWant = c.getName() // or c.name 上不存在...?)