title: javafx binding circle with Text so when I move the circle the Text moves with it
body: <p>When I move the circle the text is not relocated.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Text t = new Text(x,y, "HELLO");
  Circle c = new Circle(x,y,radius);
  
  t.xProperty().bind(c.centerXProperty());
  t.yProperty().bind(c.centerYProperty());
  </code></pre>
  
  <p>Complete code:</p>
  
  <pre><code>package netfx;  
  
  
  
  import java.util.HashMap;
  import java.util.Optional;
  import javafx.application.Application;
  import javafx.event.EventHandler;
  import javafx.geometry.Insets;
  import javafx.scene.Cursor;
  import javafx.scene.Group;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.scene.control.TextInputDialog;
  import javafx.scene.input.MouseEvent;
  import javafx.scene.layout.HBox;
  import javafx.scene.layout.StackPane;
  import javafx.scene.paint.Color;
  import javafx.scene.shape.Circle;
  import javafx.scene.text.Text;
  import javafx.scene.text.TextBoundsType;
  import javafx.stage.Stage;
  
  class RouterView  extends Group {
      private String name;
      private double x;
      private double y;
      private double radius;
  
  
  
  
      public void Routerview() {
  
      }
      RouterView(String n, double x, double y, double r){
          this.name = n;
          this.x = x;
          this.y = y;
          this.radius = r;
  
  
      }
  
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>class LinkView {
      private String name;
      private RouterView src;
      private RouterView dst;
  
  
      public void EdgeView() {
      }
      public void EdgeView(String name, RouterView s, RouterView d) {
          this.name = name;
          this.src = s;
          this.dst = d;
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code> public class NetFX extends Application {    
      Circle circle_Red, circle_Green, circle_Blue;
      double orgSceneX, orgSceneY;
      double orgTranslateX, orgTranslateY;
  
  
  
      HashMap&lt;String, RouterView&gt; routers = new HashMap&lt;String, RouterView&gt;();
      HashMap&lt;String, LinkView&gt; links = new HashMap&lt;String, LinkView&gt;();
      HBox hBox = new HBox(); 
      Group root = new Group();
  
  
  
      public String getRouterName(String msg){
          TextInputDialog dialog = new TextInputDialog(" Router Name ");
          dialog.setTitle("Router Name");
          dialog.setHeaderText("Topology manager");
          dialog.setContentText(msg);
          Optional&lt;String&gt; result = dialog.showAndWait();         
  
              if (result.isPresent()){
                  return result.get();
              }
              return null;         
  
      }
  
  
      @Override
      public void start(Stage primaryStage) {     
          hBox.setSpacing(10.0);
          Button addBtn  = new Button("ADD NODE");
          addBtn.setOnAction((event) -&gt; { 
              String name = getRouterName("Enter Router Name: ");
              if (name != null) {
                  AddRouter(name, 300,300,60);                             
                  primaryStage.show();
              }
          });
  
          Button delBtn  = new Button("ADD EDGE");
          delBtn.setOnAction((event) -&gt; { 
              String sname = getRouterName("Enter Source Router: ");
              RouterView sp = routers.get(sname);
              System.out.println(sname+" = "+sp);
              if (sp != null) {
                  String dname = getRouterName("Enter Destination Router: ");
                  RouterView dp = routers.get(dname);
                  System.out.println(dname+" = "+dp);
                  if (dp != null) {
                      //EdgeView e = AddEdge(sp,dp);
                      //edges.put(sname+"-"+dname,e);
                      primaryStage.show();
                  }
              }
          });
  
  
  
          Button saveBtn = new Button("SAVE TOPOLOGY");                
          Button exitBtn = new Button("EXIT");
          exitBtn.setOnAction((event) -&gt; { System.exit(0);});
  
  
          hBox.setPadding(new Insets(0, 20, 10, 20)); 
          hBox.getChildren().addAll(addBtn,delBtn,saveBtn, exitBtn);                        
          root.getChildren().addAll(hBox);         
          //primaryStage.setResizable(false);
          primaryStage.setScene(new Scene(root, 400,350));         
          primaryStage.setTitle("TOPOLOGY MANAGER");
          primaryStage.show();
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  
  
      public void AddRouter(String name, double x, double y, double r){       
          RouterView router = new RouterView(name,x,y,r);
          Circle c = new Circle(r, Color.GREEN);        
          c.setCenterX(x);
          c.setCenterY(y);
          Text t = new Text(x-10, y, name);                          
          c.setOnMousePressed(circleOnMousePressedEventHandler);
          c.setOnMouseDragged(circleOnMouseDraggedEventHandler);
          c.centerXProperty().bind(t.xProperty());
          c.centerYProperty().bind(t.yProperty());  
  
          root.getChildren().addAll(c,t);
          routers.put(name,router);    
      }
  
  
      public void AddEdge(){
  
      }
  
  
      EventHandler&lt;MouseEvent&gt; circleOnMousePressedEventHandler =  new 
      EventHandler&lt;MouseEvent&gt;() {
  
          @Override
          public void handle(MouseEvent t) {
              orgSceneX = t.getSceneX();
              orgSceneY = t.getSceneY();
              orgTranslateX = ((Circle)(t.getSource())).getTranslateX();
              orgTranslateY = ((Circle)(t.getSource())).getTranslateY();
              System.out.println("orgSceneX = "+orgSceneX);
              System.out.println("orgSceneY = "+orgSceneY);
              System.out.println("orgTranslateX = "+orgTranslateX);
              System.out.println("orgTranslateY = "+orgTranslateY);
          }
      };
  
      EventHandler&lt;MouseEvent&gt; circleOnMouseDraggedEventHandler =   new 
      EventHandler&lt;MouseEvent&gt;() {
  
          @Override
          public void handle(MouseEvent t) {
              double offsetX = t.getSceneX() - orgSceneX;
              double offsetY = t.getSceneY() - orgSceneY;
              double newTranslateX = orgTranslateX + offsetX;
              double newTranslateY = orgTranslateY + offsetY;
              System.out.println("offsetX = "+offsetX);
              System.out.println("offsetY = "+offsetY);
              System.out.println("newTranslateX = "+newTranslateX);
              System.out.println("newTranslateY = "+newTranslateY);
  
              ((Circle)(t.getSource())).setTranslateX(newTranslateX);
              ((Circle)(t.getSource())).setTranslateY(newTranslateY);            
          }
      };
  }
  </code></pre>