Skip to main content

JavaFX dynamical GUI creation

3 replies [Last post]
makados
Offline
Joined: 2006-06-20
Points: 0

Hi. I write a little IM-client, and need to show contact list. ListBox is not a good idea because of design purposes.
I have a Box widget, in which different GUI components are located. And want to display every contact as BorderPanel or something like this. How can I dynamically add widgets to Box' content?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
makados
Offline
Joined: 2006-06-20
Points: 0

I need a little modification of suggested code

[code]
import javafx.ui.*;

var list = ["t1", "t2"];
var text = "Text";

Frame{
title: "Box Example"
width: 200
height: 200

content: BorderPanel{

top: Box{
// top instead of center
content: bind foreach( p in list) SimpleLabel{ text: p }
//Label changed to SimpleLabel, for example
orientation: VERTICAL
}
bottom: FlowPanel{
content: [
Button{
text: "Add"
action: operation(){
insert text into list;
}
}
]
}
}

visible: true
}
[/code]

and adding a new element stops working. After a small investigation:) i've found that Box.preferredSize doesn't changes. But box size has to depend on contacts number, so I need ability to change preferredSize on runtime. After some hours on this problem I didn't get any good result.

Does someone knows how to change preferredSize on runtime?

Message was edited by: makados

Message was edited by: makados

alexsch
Offline
Joined: 2007-07-12
Points: 0

The following example adds elements to the Box:

[code]
import javafx.ui.*;

var list = [];
var text = "Text";

Frame{
title: "Box Example"
width: 200
height: 200

content: BorderPanel{
top: FlowPanel{
content: [ Label{ text: "Name"}, TextField{ columns: 10 text: bind text }]
}
center: Box{
content: bind foreach( p in list) Label{ text: p }
orientation: VERTICAL
}
bottom: FlowPanel{
content: [
Button{
text: "Add"
action: operation(){
insert text into list;
}
}
]
}
}

visible: true
}
[/code]

makados
Offline
Joined: 2006-06-20
Points: 0

thanks, it's exactly what i need.