« I Hear Voices - RIAs are the Future (Remix) | Main | BindListBoxToSequence (JavaFX Puzzler 3) Results and Sample Solution »

November 14, 2007

Comments

Lucas Benedicic

And so, the entire solution:


/*
* ListBoxModel.fx
*
* Created on Nov 14, 2007, 7:23:04 PM
*/

package javafxpuzzler;

import javafx.ui.*;


public class ListBoxModel
{
attribute entries : String *;
attribute newEntry : String;
}

Frame {
var model = ListBoxModel {
entries: ["Pepe", "Coco"]
}
title: "ListBox Example"
content: BorderPanel {
bottom: ListBox {
cells: bind foreach (entry in model.entries)
ListCell {
text: entry
}
}
center: FlowPanel {
content:
[Button {
text: "Add Element"
action: operation ( ) {
insert model.newEntry as last into model.entries;
}
},
TextField {
columns: 30
value: bind model.newEntry
text: bind model.newEntry
action: operation ( ) {
insert model.newEntry as last into model.entries;
}
},
RigidArea {
width: 5
}]
}
}
visible: true
}

Lucas Benedicic

Because of the hurry in sending the solution, I've found out that with this line:

text: bind model.newEntry

inside the TextField component of the FlowPanel, it works without "random" behavior ... :-)

Lucas Benedicic

/*
* ListBoxModel.fx
*
* Created on Nov 14, 2007, 7:03:04 PM
*/

package javafxpuzzler;

import javafx.ui.*;


public class ListBoxModel
{
attribute entries : String *;
attribute newEntry : String;
}

Frame {
var model = ListBoxModel {
entries: ["Pepe", "Coco"]
}
title: "ListBox Example"
content: BorderPanel {
bottom: ListBox {
cells: bind foreach (entry in model.entries)
ListCell {
text: entry
}
}
center: FlowPanel {
content:
[Button {
text: "Add Element"
action: operation ( ) {
insert model.newEntry as last into model.entries;
}
},
RigidArea {
width: 5
},
TextField {
columns: 30
value: bind model.newEntry
action: operation ( ) {
insert model.newEntry as last into model.entries;
}
},
RigidArea {
width: 5
}]
}
}
visible: true
}

codecraig

I'm gonna work on this on my own since I already won a copy of the book :)

The comments to this entry are closed.

Categories