3

JavaFXの特定の時点でノードを取得するには?
Java Swing にはメソッドがありSwingUtilities.getDeepestComponentAtます。SwingとしてサポートするJavaFXメソッドはありますか?

JavaFxでは、 javafx.scene.Node.impl_pickNode(double parentX, double parentY) しかし、それは返しますnull

シンペット コード:

scene.getRoot().impl_pickNode(428.0, 278.0);

例:

public class Main extends Application {

public static void main(String[] args) {        
    Application.launch(args);   
}

@Override
  public void start(Stage stage) {
    stage.setTitle("ComboBoxSample");
    Scene scene = new Scene(new Group(), 450, 250);

    TextField notification = new TextField ();
    notification.setText("Label");

    notification.clear();

    GridPane grid = new GridPane();
    grid.setVgap(4);
    grid.setHgap(10);
    grid.setPadding(new Insets(5, 5, 5, 5));
    grid.add(new Label("To: "), 0, 0);
    grid.add(notification, 1, 0);

    scene.setOnMouseClicked(mouseHandler);

    Group root = (Group) scene.getRoot();
    root.getChildren().add(grid);
    stage.setScene(scene);
    stage.show();

  }

EventHandler<MouseEvent> mouseHandler = new EventHandler<MouseEvent>() {

    @Override
    public void handle(MouseEvent mouseEvent) {
        System.out
                .println(mouseEvent.getEventType() + "\n" + "X : Y - "
                        + mouseEvent.getX() + " : " + mouseEvent.getY()
                        + "\n" + "SceneX : SceneY - "
                        + mouseEvent.getSceneX() + " : "
                        + mouseEvent.getSceneY() + "\n"
                        + "ScreenX : ScreenY - " + mouseEvent.getScreenX()
                        + " : " + mouseEvent.getScreenY());
        Scene scene = (Scene) mouseEvent.getSource();
        Object node =  scene.getRoot().impl_pickNode(428.0, 278.0);
        if(node != null)
            System.out.println("node is: " + node.getClass().getName().toString());
        else{
            System.out.println("node is NULL");
        }




        Iterator<Window> windows = Window.impl_getWindows();
        while (windows.hasNext()) {
            Window wnd = windows.next();

            if (wnd instanceof Stage) {
                Stage stage = (Stage) wnd;
                System.out.println("---> " + stage.getTitle());
            }

        }
    }

};  

}

4

0 に答える 0