I want same thing that asked in this post track changes of nodes bound in JavaFX
I have something like this : (Edited) SSCCE:
public class FloatCircle {
Node node;
Circle rectangle;
Bounds localToScreen;
static ArrayList<ObjectBinding> list = new ArrayList<>();
private ObjectBinding<Bounds> boundsInScene ;
Pane root ;
public FloatCircle(Node node,Pane root) {
this.node = node;
this.root =root;
this.rectangle = new Circle();
this.rectangle.setManaged(false);
initSetting();
}
public Circle getFloatCircle() {
return rectangle;
}
public void initSetting() {
boundsInScene = Bindings.createObjectBinding(
() -> node.localToScene(node.getBoundsInLocal()),
node.localToSceneTransformProperty(),
node.boundsInLocalProperty());
boundsInScene.addListener(new ChangeListener<Bounds>() {
@Override
public void changed(ObservableValue<? extends Bounds> observable, Bounds oldValue, Bounds newValue) {
setLocation(newValue);
System.err.println("CHANGED!!!!!!");
}
});
localToScreen = node.localToScene(node.getBoundsInLocal());
setLocation(localToScreen);
addCircle();
}
public void setLocation(Bounds localToScreen) {
int r = 10;
rectangle.setCenterX(localToScreen.getMinX() - r);
rectangle.setCenterY(localToScreen.getMinY() - 5);
rectangle.setRadius(r);
// return rect;
}
public void addCircle(){
root.getChildren().add(rectangle);
}
}
public class SelfContained extends Application {
ArrayList<Node> nodes = new ArrayList<>();
@Override
public void start(Stage primaryStage) {
Button btn = new Button();
StackPane root = new StackPane();
root.getChildren().add(btn);
nodes.add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
for (int i = 0; i < nodes.size(); i++) {
Node n = nodes.get(i);
FloatCircle floatCircle = new FloatCircle(n, root);
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
but the problem is changed method doesn't called correctly...It is called just one time....if I add this code in changed method instead of the old one It is called correctly...But it is very very slow
FloatCircle fc = new FloatCircle(node);
fc.rectangle = rectangle ;
fc.setLocation(newValue, directionID, alignment);
Can anyone help me? Thank's...