Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8099546

Implement an ability to determine what Node is located at a random point of the scene.


    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: fx1.2.1
    • Fix Version/s: None
    • Component/s: javafx
    • Environment:

      Windows XP 32bit


      There is no documented ability to determine what Node is located at a random point (x, y) of the scene. We have to use the undocumented java.util.List impl_pick(float, float) method of the javafx.scene.Scene class.

      This solution is not optimal.

      Firstly, this functionality is not public and might be changed by JavaFX authors.

      Secondly, the returned list of objects-nodes does not contain Nodes that are disabled. The following example demonstrates this limitation:

      There is the "Big button" button on the scene. Under the button there is another button that makes the "Big button" button enabled/disabled when you click it. Clicking this button also determines the object under the point under which "Big button" is visually located. Corresponding calculations are made by means of the HitTest function. The HitTest result is printed below. If "Big button" is disabled, the impl_pick method of the scene returns an empty list, otherwise - the Nodes list under a point beginning from the top one.


      import javafx.stage.Stage;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.text.Text;

      var bigButton = Button
      translateX: 0,
      translateY: 0,
      width: 100,
      height: 100,
      text: "Big button"

      var info = Text
      translateX: 0,
      translateY: 200

      function HitTest(x: Number, y: Number): String
      var hitTestPoint = bigButton.localToScene(x, y);
      var list = bigButton.scene.impl_pick(hitTestPoint.x, hitTestPoint.y);
      var size = list.size();
      if (size > 0)
      return list.get(0).getClass().getName()
      return "<scene>";

      var actButton = Button
      translateX: 0,
      translateY: 110,
      width: 300,
      height: 50,

      var actButtonText = "Disable \"Big button\" & perform hitTest";
      text: bind actButtonText,

      action: function()
      actButtonText = if (bigButton.disable) "Disable \"Big button\" & perform hitTest" else "Enable \"Big button\" & perform hitTest";
      bigButton.disable = not bigButton.disable;
      info.content = "HitTest: {HitTest(50, 50)}";

      title: "HitTest";
      scene: Scene
      width: 600,
      height: 400,
      content: [bigButton, actButton, info]

      We'd like to have a universal documented method of detecting a Node under a point without the limitations of the method we are using now. For example:
      javafx.scene.Node[] javafx.scene.Scene.hitTest(Number, Number).


          Issue Links



              • Assignee:
                psafrata Pavel Ĺ afrata
                mattjfx Matt (Inactive)
              • Votes:
                0 Vote for this issue
                1 Start watching this issue


                • Created: