Skip to main content

I need to get the current width of some Node after it draw in the canvas

3 replies [Last post]
m7md_3cs_fci
Offline
Joined: 2008-05-19
Points: 0

Hi all,
how can i get the currentWidth of some Node after the drawing in some Canvas??

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

One way is using binding mechanism

[i]currentWidth: bind width with inverse[/i]
------------------------------------------------------------------------------
[code]
import javafx.ui.*;
import javafx.ui.canvas.*;

var width = 0.0;

Frame{
title: "Hello"
content: BorderPanel{
top: Label{ text: bind "current width: {width}"}
center: Canvas{
content: Text{
x: 10
y: 20
content: "Hello World!"
fill: Color.BLUE
currentWidth: bind width with inverse

}
}
}
visible: true
}
[/code]

m7md_3cs_fci
Offline
Joined: 2008-05-19
Points: 0

thanks, but is this the only solution

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

The second one is not so good solution:

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

var text = Text{
x: 10
y: 20
content: "Hello World!"
fill: Color.BLUE
};

Frame{
title: "Hello World!"
content: BorderPanel{
center: Canvas{
content: text
}
}
visible: true
}

System.out.println("currentWidth: {text.currentWidth}");
[/code]