JavaFX - 扩展舞台,但继承的方法未定义
JavaFX - Extends Stage, but inherited method is undefined
我正在使用 Java8 使用 JavaFX,我有一个 class,其中 Stage 被扩展了。我从另一个学生那里得到这段代码,它对其他人都很好用,但对我来说,我在 setAlwaysOnTop 上遇到错误。它说该方法未定义,但它是从 Stage 继承的。似乎只有那个方法给出了这个错误。
使用图片会更容易,但我还不能 post 图片,所以我不得不复制粘贴相关代码:
public class NotificationWindow extends Stage {
public void showNotification(){
Rectangle2D screenBounds=Screen.getPrimary().getVisualBounds();
this.setAlwaysOnTop(true); //Error here
this.setX(screenBounds.getMaxX()-scene.getWidth());
this.setY(screenBounds.getMaxY()-scene.getHeight());
this.show();
}
}
alwaysOnTop
property 是在 JavaFX 8 update 20 中引入的。所以您可能使用的是更早的版本。更新到最新的 JavaFX 版本,它应该可以识别该方法。
我正在使用 Java8 使用 JavaFX,我有一个 class,其中 Stage 被扩展了。我从另一个学生那里得到这段代码,它对其他人都很好用,但对我来说,我在 setAlwaysOnTop 上遇到错误。它说该方法未定义,但它是从 Stage 继承的。似乎只有那个方法给出了这个错误。
使用图片会更容易,但我还不能 post 图片,所以我不得不复制粘贴相关代码:
public class NotificationWindow extends Stage {
public void showNotification(){
Rectangle2D screenBounds=Screen.getPrimary().getVisualBounds();
this.setAlwaysOnTop(true); //Error here
this.setX(screenBounds.getMaxX()-scene.getWidth());
this.setY(screenBounds.getMaxY()-scene.getHeight());
this.show();
}
}
alwaysOnTop
property 是在 JavaFX 8 update 20 中引入的。所以您可能使用的是更早的版本。更新到最新的 JavaFX 版本,它应该可以识别该方法。