Skip to main content

Binding to a node's global coordinates

2 replies [Last post]
Joined: 2003-06-10

I have a Node that is deeply nested within Groups. How would I go about writing a bind expression to the Node's global coordinates? That is, something that would trigger whenever the node or any of its ancestor groups were transformed.

Reply viewing options

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

Is it what are you looking for?

import javafx.ext.swing.*;
import javafx.scene.paint.*;
import javafx.scene.geometry.*;

var x = 10;

Frame {
title: "MyApplication"
width: 200
height: 200

content: BorderPanel{
center: Canvas {
content: [
Circle {
centerX: bind x
centerY: 100
radius: 10
fill: Color.ORANGE

bottom: Slider {
minimum: 10
maximum: 190
value: bind x with inverse
visible: true

Joined: 2003-06-10


I haven't tried this code yet, but it doesn't look like what I'm looking for. I'm talking about Nodes deep within a Group hierarchy (here you have a Circle inside a Canvas inside a BorderPanel, but no Groups are involved).

If you had something like Group { content : [Group {content: [Circle {}] translateX:10}] translateX : 20}, I would want a bind (and this has nothing to do with inverse binds) on the Circle's global (as opposed to local) x that would recalculate any time either the Circle's x or any of its parent groups were moved.

I've figured out how to get a node's global coordinates through SgNode.localToGlobal, but I'm not sure how to bind to changes in the result of that function.