Binding data to UI components

Hi guys,

is there a way of binding data to components permanently in terms of sth. like this…:

String labText = “Label Text”;
private Label label01 = new Label(labText);

// some action modifying the string…

public void executeAction()
{
labText = “Text changed”; // label within UI component remains :frowning:
}

Thanx for your help in advance, Florian!

Hi Florian!

You can bind any field to a Property, for instance an ObjectProperty. To expand your example:


ObjectProperty labProperty = new ObjectProperty("Label Text");
private Label label01 = new Label();
...
// Bind the property to the label
label01.setPropertyDataSource(labProperty);
...
// some action modifying the string...
...
public void executeAction()
{
    labProperty.setValue("Text changed");   // Label is updated
}

HTH,
/Jonatan

Hi Jonathan,

thanx for your reply - unfortunately this did not resolve my issue, as using this approach allows “only” to bind the most important properties (which in case of the Label is the text…);

but what if I want to bind the size of a label to a certain property? Or the width/height of a container - is there a way to do so?

Thanx for your highly appreciated help, Florian!

Yes, unfortunately you cannot bind properties such as width/height/etc, only the actual value of a field.

You can, however set the size of any component relatively, say width=50% means that the component will take 50% of the available width (of its allocated space). Or if you set the width to ‘null’ (== undefined) the component, e.g. Label in this instance, will be just wide enough to fit the text that is its value.

/Jonatan