import groovy.beans.Bindable;
import groovy.swing.SwingBuilder
import javax.swing.WindowConstants as WC
import java.awt.BorderLayout as BL
@Bindable class Model{
List comboBoxValues = ['1','2','3']
}
Model m=new Model()
swing = new SwingBuilder()
frame = swing.frame(size:[200, 100],title:'Enviroment
Helper',defaultCloseOperation:WC.EXIT_ON_CLOSE) {
borderLayout()
c1 = comboBox(items:model.comboBoxValues,actionPerformed: {println it},
constraints: BL.NORTH)
comboBox(items:m.comboBoxValues,actionPerformed: {println it},
constraints: BL.SOUTH)
noparent {
bean(c1, elements: bind {model.comboBoxValues})
}
}
frame.show()
--
View this message in context: http://groovy.329449.n5.nabble.com/SwingBuilder-Binding-of-ComboBox-items-does-not-work-empty-tp2804857p2805737.html
Sent from the groovy - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Ad up to the fact that items: copies the values form the original collection
then even changing the value of m.comboBoxValues will accomplish nothing.
What you can do is listen to changes on the List itself. You can either use
GlazedLists' EventList and its companion models (a great choice btw) or
Groovy's own ObservableList, like this
import groovy.swing.SwingBuilder
import groovy.beans.Bindable
import java.beans.PropertyChangeListener
class Model{
@Bindable ObservableList comboBoxValues = ['1', '2', '3'] as
ObservableList
}
def m = new Model()
new SwingBuilder().edt {
frame(title: 'Foo', pack:true, visible: true) {
borderLayout()
comboBox(id: 'c1', constraints: CENTER, items: m.comboBoxValues,
actionPerformed: {println c1.selectedItem})
textField(columns: 20, constraints: NORTH, actionPerformed: {e ->
m.comboBoxValues << e.source.text})
noparent {
m.comboBoxValues.addPropertyChangeListener({e ->
// update the underlying ComboBoxModel
switch(e.typeAsString) {
case 'ADDED': /*handle new item*/ break;
case 'REMOVED': /*handle item deleted*/ break;
case 'UPDATED': /*an item changed internally*/ break;
case 'CLEARED': /*all items are gone*/ break;
case 'MULTI_ADD': /*several items added*/ break;
case 'MULTI_REMOVE': /*several items removed*/ break;
}
} as PropertyChangeListener)
}
}
}
Cheers,
Andres
--
View this message in context: http://groovy.329449.n5.nabble.com/SwingBuilder-Binding-of-ComboBox-items-does-not-work-empty-tp2804857p2827393.html