または、単純な「ハック」を使用して、ボタンをプログラムでクリックすることもできます。「Util」クラスでこのメソッドを作成します。
public static void click(javafx.scene.control.Control control) {
java.awt.Point originalLocation = java.awt.MouseInfo.getPointerInfo().getLocation();
javafx.geometry.Point2D buttonLocation = control.localToScreen(control.getLayoutBounds().getMinX(), control.getLayoutBounds().getMinY());
try {
java.awt.Robot robot = new java.awt.Robot();
robot.mouseMove((int)buttonLocation.getX(), (int)buttonLocation.getY());
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.mouseMove((int) originalLocation.getX(), (int)originalLocation.getY());
} catch (Exception e) {
e.printStackTrace();
}
}
次に、ボタンを「クリック」するには、ボタンをパラメーターとして渡してメソッド click を呼び出すだけです。