假设我使用SwingBuilder声明对象,如下所示:
swing.button(id:'something')
我知道我可以通过打电话从Component获得SwingBuilder:
swing."something"
但是如何从Component的一个实例返回到它的id作为一个字符串呢?
Component c = getMyButton()
String whatIWant = c.id //Property doesn't exist
String attempt2 = c['id'] //Property doesn't exist发布于 2017-05-27 01:31:48
我相信你要找的是名字,所以Component#getName()应该做你想做的事。
例如:
Component c = getMyButton()
String whatIWant = c.getName() // or c.name不幸的是,这还没有文档化,但是这似乎是Groovy SwingBuilder源代码所做的。,尽管属性 (Component上不存在?)
https://stackoverflow.com/questions/44202102
复制相似问题