track changes of nodes bound in JavaFX

I need to track changes in absolute position and size of a node in javafx.Any change that is caused by resizing window or user manipulation,...

 node.boundsInLocalProperty().addListener(new ChangeListener<Bounds>() {

 @Override
 public void changed(ObservableValue<? extends Bounds> observable,Bounds oldValue, Bounds newValue) {

 System.err.println("Changed!");


 }

 });


 node.boundsInParentProperty().addListener(new ChangeListener<Bounds>() {

 @Override
 public void changed(ObservableValue<? extends Bounds> observable,Bounds oldValue, Bounds newValue) {

 System.err.println("Changed!");


 }

 });

I tried these solutions but doesn't work!

please help me, thanks.

Answers


This is quite heavy on performance, so I do not recommend doing this with a large number of nodes in the scene graph, but:

ObjectBinding<Bounds> boundsInScene = Bindings.createObjectBinding(
    () -> node.localToScene(node.getBoundsInLocal()),
    node.localToSceneTransformProperty(),
    node.boundsInLocalProperty());

boundsInScene.addListener((obs, oldBounds, newBounds) -> 
    System.err.println("Changed!"));

You can also do the following, which might be less prone to premature garbage collection:

ChangeListener<Object> listener = (obs, oldValue, newValue) -> 
    System.err.println("New bounds in scene: "+node.localToScene(node.getBoundsInLocal()));
node.localToSceneTransformProperty().addListener(listener);
node.boundsInLocalProperty().addListener(listener);

Need Your Help

UITestControlNotAvailableException is received when TC is included in Ordered Test

wpf mstest coded-ui-tests specflow ordered-test

I use SpecFlow with Coded UI to create some automated functional tests for a WPF application. Test case execution is performed using MsTest and Visual Studio Premium 2012.

Emacs Clojure mode tab-indentation huge in some cases

emacs clojure

I'm using Emacs' Clojure mode with SLIME and swank-clojure. I have an issue with the indentation. Most of the time the indentation does what I want: it indents with 2 spaces when I press TAB. But ,...