问题
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