Skip to main content

Modify components in run time.

2 replies [Last post]
zinyak
Offline
Joined: 2008-03-05
Points: 0

Having the following code:

<br />
var myFrame = Frame {<br />
	var: me<br />
    title: bind "JavaFX"<br />
    GridPanel {<br />
        var: pannel<br />
        rows: 2<br />
        columns: 1<br />
        cells: [<br />
	        Label {<br />
	            text: "Change me!"}]},<br />
	        Button {<br />
	            text: "Change"<br />
	            action: operation() {<br />
	            	System.out.println(pannel.cells[0]); // shows a label "Change me!"<br />
	            	pannel.cells[0] = new Button {<br />
	            		text: "Changed!"<br />
						action: operation() {/*void*/}<br />
	            	};<br />
	            	System.out.println(pannel.cells[0]); // shows a button "Changed!"<br />
	            }<br />
	        }<br />
		]<br />
	}<br />
    visible: true<br />
}<br />

I get the messages indicating that cells[0] have changed, however the view doesn't reflect the change.

Is it possible to change components at run time?

Thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12
Points: 0

The idea is to bind an array of widgets with cells attribute from GridPanel class:

[code]
import javafx.ui.*;
import java.lang.System;

var pannel = [];
pannel = [
Label {
text: "Change me!"
}, Button {
text: "Change"
action: operation() {
System.out.println(pannel[0]);
// shows a label "Change me!"
delete pannel[0];
insert Button {
text: "Changed!"
action: operation() {/*void*/}
} before pannel[0];

//insert Button{ text: "Text"} into pannel;
System.out.println(pannel[0]);
// shows a button "Changed!"
}
}
];

var myFrame = Frame {
var: me
title: bind "JavaFX"
content: GridPanel {
rows: 2
columns: 1
cells: bind pannel
}
visible: true
};[/code]

zinyak
Offline
Joined: 2008-03-05
Points: 0

Hi alexsch

Thank you for your reply, it worked at the end with a lot of trouble, let me eplain:

Im using eclipse (personally i don't like betbeans) it happens that with the libraries shipped on the plugin:
[code]
Filters.jar
javafxrt.jar
swing-layout.jar
[/code]

The code you gave me doesn't work, i took the swing-layour library from the netbeans plugin:
[code]
swing-layout-1.0.3.jar
[/code]
And it worked like a charm.

Having this i downloaded the SVN version to get the lasted libraries and keep myself up to date, but in that version the libraries shipped included :
[code]
swing-layout.jar
[/code]

I don't know which one is the recent one all i know is that your code is working with 1.0.3.

Best regards.

Message was edited by: zinyak (corrected a library name)

Message was edited by: zinyak