title: JavaFX How make a Node to be always in front and fully visible?
body: <p>This program generates a chart and displays the coordinate values when the mouse enters the plotted dots by replacing the dot for a label.</p>
  
  <p>But the problem is that the label does not appear completely if the dot is in the border of the chart.</p>
  
  <p>I couldn't solve this issue using the <code>toFront()</code> and <code>toBack()</code> functions.</p>
  
  <p>My code was adapted from the answer to this question JavaFX LineChart Hover Values, which has the same bug.</p>
  
  <p>Chart.java</p>
  
  <pre><code>import javafx.application.Application;
  import javafx.scene.Scene;
  import javafx.scene.chart.LineChart;
  import javafx.scene.chart.NumberAxis;
  import javafx.scene.chart.XYChart;
  import javafx.stage.Stage;
  
  public class Chart extends Application {
  
  @Override
  public void start(Stage stage) {
  
      // Random chart
      // Defining the Axis
      final NumberAxis xAxis = new NumberAxis();
      final NumberAxis yAxis = new NumberAxis();
      // Creating the chart
      LineChart&lt;Number, Number&gt; lineChart = new LineChart(xAxis, yAxis);
  
      // This didn't solve the bug
      xAxis.toBack();
      yAxis.toBack();
  
      // Preparing the series
      XYChart.Series series = new XYChart.Series();
      series.setName("Chart");
  
      for (double x = 0; x &lt;= 10; x++) {
          double y = Math.random() * 100;
          XYChart.Data chartData;
          chartData = new XYChart.Data(x, y);
          chartData.setNode(new ShowCoordinatesNode(x, y));
          series.getData().add(chartData);
      }
  
      // Adding series to chart
      lineChart.getData().add(series);
  
      Scene scene = new Scene(lineChart, 800, 600);
      stage.setScene(scene);
      stage.show();
  }
  
  public static void main(String[] args) {
      launch(args);
  }
  }
  </code></pre>
  
  <p>ShowCoordinatesNode.java</p>
  
  <pre><code>import java.text.DecimalFormat;
  import javafx.event.EventHandler;
  import javafx.scene.Cursor;
  import javafx.scene.control.Label;
  import javafx.scene.input.MouseEvent;
  import javafx.scene.layout.StackPane;
  
  public class ShowCoordinatesNode extends StackPane {
  
  public ShowCoordinatesNode(double x, double y) {
  
      final Label label = createDataThresholdLabel(x, y);
  
      setOnMouseEntered(new EventHandler&lt;MouseEvent&gt;() {
          @Override
          public void handle(MouseEvent mouseEvent) {
                  setScaleX(1);
                  setScaleY(1);
                  getChildren().setAll(label);
                  setCursor(Cursor.NONE);
                  toFront(); // This didn't solve the bug
          }
      });
      setOnMouseExited(new EventHandler&lt;MouseEvent&gt;() {
          @Override
          public void handle(MouseEvent mouseEvent) {
                  getChildren().clear();
                  setCursor(Cursor.CROSSHAIR);
          }
      });
  }
  
  private Label createDataThresholdLabel(double x, double y) {
      DecimalFormat df = new DecimalFormat("0.##");
      final Label label = new Label("(" + df.format(x) + "; " + df.format(y) + ")");
      label.getStyleClass().addAll("default-color0", "chart-line-symbol", "chart-series-line");
      label.setStyle("-fx-font-size: 10; -fx-font-weight: bold;");
      label.setMinSize(Label.USE_PREF_SIZE, Label.USE_PREF_SIZE);
      label.setId("show-coord-label");
      return label;
  }
  }
  </code></pre>