First call to JavaFx Stage::setY inconsistent on Linux - workaround?

↘锁芯ラ 提交于 2020-01-05 04:28:10

问题


When I run the following program, there is a 50% chance that the first click on the button will result in the Window being moved about 10 pixels below (using Ubuntu linux, Oracle JDK 1.8, JavaFx 8.0.102-b14). After that, each click correctly results in a small upwards shift.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class JavaFxTest extends Application {
  @Override
  public void start(Stage myStage) {
    myStage.setTitle("Hello World!");
    Button myButton = new Button();
    myButton.setText("Click!");
    myButton.setOnAction(event -> myStage.setY(myStage.getY() - 1));
    StackPane myStackPane = new StackPane();
    myStackPane.getChildren().add(myButton);
    myStage.setScene(new Scene(myStackPane, 300, 250));
    myStage.show();
  }

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

The bug is demonstrated in the following video: https://youtu.be/c7QFuya7V4M

With awt, and swing I ran into similar trouble, and posted the question here: Workaround for bug_id=4806603 regarding getBounds() and setBounds() on Linux?

Does anybody have a workaround in order to achieve correct window placement?

来源:https://stackoverflow.com/questions/39086597/first-call-to-javafx-stagesety-inconsistent-on-linux-workaround

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!