1

i have the following code

in the model

@Bindable boolean readOnly

in the view

checkBox(text: 'Read Only', constraints:'wrap',selected:bind(target: model, targetProperty:'readOnly'))

in the controller

new groovy.swing.SwingBuilder().frame(title:'File opened',pack:true,show:true){
  panel(layout: new MigLayout('fill'), border: titledBorder('Content')){
    separator(constraints:"cell 0 1")
    textArea(text: part1 , editable: false)
    separator(constraints:"cell 0 2")
    textArea(text: part2 , editable: false)
    separator(constraints:"cell 0 1")
    t1 = textArea(text: part3 , editable: "${model.readOnly}",columns:50)
    separator(constraints:"cell 0 2")
    t2 = textArea(text: part4 , editable: "${model.readOnly}")
    separator(constraints:"cell 0 3")
    button('Save!', actionPerformed: save, constraints: 'span 5, bottom, right')
  }
}

but its always enabled , doesnt matter if checkbox is selected or not.

system.out.println("${model.readOnly}")

shows true and false correctly but for some reason on the frame its always set to true

note: also assignment boolean a = "${model.readOnly}" sets a always to true , or if "${model.readOnly}" == true or if ("${model.readOnly}") work as its always true

oh and also setting size in the frame such as

new groovy.swing.SwingBuilder().frame(title:'File opened',pack:true,show:true, size : [640,480]){

doesnt work either

tim_yates
  • 167,322
  • 27
  • 342
  • 338

1 Answers1

2

(a) The text areas need to be bound, not just set. As written it will read the value only once.

t1 = textArea(text: part3 , editable: bind (source: model, sourceProperty:'readOnly') ,columns:50)

(b) the one more thing, combining pack aid size generally doesn't work. Remove the pack:true from the declaration whenever you declare a size.

shemnon
  • 5,318
  • 4
  • 28
  • 37