我试图将我的应用程序中心设置在屏幕中间,尽管我可以清楚地看到应用程序应该在左边,但我显然想出了自己在StackOverFlow上其他线程上提出的通用解决方案。
我现在使用的屏幕是1920x1080,但是在1366x766屏幕上也发生过同样的事情。
Rectangle2D p = Screen.getPrimary().getVisualBounds();
double w = p.getWidth() / 1.5;
double h = p.getHeight() / 1.5;
stage.setWidth(w);
stage.setHeight(h);
stage.setX(p.getWidth()/2 - stage.getWidth()/2);
stage.setY(p.getHeight()/2 - stage.getHeight()/2);
在我的情况下,舞台比例为1280x720 有什么原因会发生这种情况吗?预先感谢。
编辑:好的,我发现它工作得很好(根据某人的评论),问题出在我放置在原始应用程序左侧的Windows应用程序栏上位置,应用程序是中心。