【问题标题】:Javafx stage resizeable false and maximized true hides the taskbarJavafx 阶段可调整大小的 false 和最大化的 true 隐藏任务栏
【发布时间】:2016-03-24 10:16:49
【问题描述】:

在我的 JavaFX FXML 应用程序中,当我将 resizable 设置为 false 并将最大化设置为 true 时,窗口变为最大化但任务栏被隐藏。我在带有 JDK 1.8.60 的 Windows 7 64 位上使用 Netbeans 8.0.2

在 Netbeans 中,我按照步骤创建了一个新的 JavaFX FXML 应用程序。对于生成的默认代码,我在 start 函数中添加了以下两行。

stage.setResizable(false);
stage.setMaximized(true);

因此最终的启动函数如下

public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().
        getResource("FXMLDocument.fxml"));

    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.setResizable(false);
    stage.setMaximized(true);
    stage.show();
}

现在,当我运行应用程序时,窗口最大化,标题栏可见,但任务栏不可见。我应该如何解决这个问题,即使任务栏可见?

【问题讨论】:

  • 我无法重现这一点 - 您的代码正确地最大化窗口,标题按钮仍然显示。只有当我将stage.setMaximized(true); 替换为stage.setFullScreen(true); 时,窗口才会正确显示全屏,没有标题按钮,并且有一个注释窗口可以按ESC 关闭全屏模式。您的.fxml 文件中有什么不寻常的地方吗?最好发布一个minimal reproducible example,我们可以直接将其放入javac 以重现问题。
  • 在 Netbeans 中,我按照步骤创建了一个新应用程序,并在生成的默认代码中添加了可调整大小和最大化的代码。
  • 因此,使用上面的代码,您会收到类似“按 ESC 关闭全屏模式”的通知,并且最大化的窗口包含带有常用按钮的标题栏关闭和最小化?您在哪个操作系统上使用哪个窗口系统,您的确切 JDK 版本是什么?
  • 我可以看到标题栏,窗口最大化但看不到任务栏。我正在使用 JDK 1.8.60

标签: java javafx-8


【解决方案1】:

@JC997 有一个很好的答案,但我想改进。

使用 setWidth 和 setHeight 时,您不会阻止用户调整整个窗口的大小。在这种情况下,将 setResizeable(false) 与以下代码结合也无济于事。

您应该应用 MinMax 值来实际实现您正在寻找的东西,使用这个

Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
stage.setX(primaryScreenBounds.getMinX());
stage.setY(primaryScreenBounds.getMinY());

stage.setMaxWidth(primaryScreenBounds.getWidth());
stage.setMinWidth(primaryScreenBounds.getWidth());

stage.setMaxHeight(primaryScreenBounds.getHeight());
stage.setMinHeight(primaryScreenBounds.getHeight());

【讨论】:

    【解决方案2】:

    如果您希望舞台不可调整大小和最大化,并且任务栏可见,您可以使用我认为的以下代码:

    Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
    stage.setX(primaryScreenBounds.getMinX());
    stage.setY(primaryScreenBounds.getMinY());
    stage.setWidth(primaryScreenBounds.getWidth());
    stage.setHeight(primaryScreenBounds.getHeight());
    

    它的作用是寻找屏幕边界并将任务栏考虑在内。

    【讨论】:

      猜你喜欢
      • 2021-10-11
      • 2014-01-23
      • 1970-01-01
      • 2014-10-31
      • 1970-01-01
      • 2014-11-19
      • 2017-07-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多