Groovy SwingBuilder bind to multiple properties

落爺英雄遲暮 提交于 2019-12-07 00:21:29

You can do this sort of thing:

import groovy.beans.Bindable
import groovy.swing.SwingBuilder
import javax.swing.WindowConstants as WC

class CombinedModel {
  @Bindable String text1
  @Bindable String text2
}

def model = new CombinedModel()

SwingBuilder.build() {
    frame(title:'Multiple Bind Test', pack:true, visible: true, defaultCloseOperation:WC.EXIT_ON_CLOSE ) {
        gridLayout(cols: 2, rows: 0)

        label 'Input text 1: '
        textField( columns:10, id:'fielda' )

        label 'Input text 2: '
        textField( columns:10, id:'fieldb' )

        // Bind our two textFields to our model
        bean( model, text1: bind{ fielda.text } )
        bean( model, text2: bind{ fieldb.text } )

        label 'Button: '
        button( text:'Button', enabled: bind { model.text1 && model.text2 } )
    }
}

As you can see, that binds two textfields to fields in our model, then binds enabled for the button to be true if both text1 and text2 are non-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!