【问题标题】:Popup goes behind stage only on Mac but not on Windows/Linux in Full Screen弹出窗口仅在 Mac 上进入后台,但在 Windows/Linux 上全屏显示
【发布时间】:2013-12-18 11:41:16
【问题描述】:

我正在扩展 javafx.stage.Popup 以显示弹出消息。整个应用程序在 Windows 和 Ubuntu 上运行良好,但在 Mac 上,当应用程序全屏时,弹出窗口会落后于当前阶段。我试过使用 z-index、.toFront()、设置所有者窗口和一切。但是弹出窗口永远不会出现! javafx.stage.FileChooser 也有同样的问题。既然应用程序必须一直全屏,那么解决办法是什么?

编辑: 在另一个页面中,文本字段的光标全屏闪烁,但没有收到键入的键!这在全屏时发生!如果我失去全屏,文本字段会收到键入的键。很烦人:(请建议我是否应该提交错误或其他内容

我已经找到了弹出的解决方法,但 DirectoryChooser/FileChooser 的问题仍然存在。

这是扩展 Popup 的类:

public class PopupDisplay extends Popup
{
String Title=new String("Information");
String Prompt=new String("Prompt Text");
@FXML
private AnchorPane anchorMain;
@FXML
private Label lblTitle=new Label();
@FXML
private Font x1;
@FXML
private Label lblPrompt=new Label();
@FXML
private Button btnOk;
@FXML
private GridPane gridMain;
@FXML
private HBox hboxTitle;
static PopupDisplay instance;
private ColorDxDesktop application;
public void show(Stage stage, String titleKey,String promptKey, Locale enLocale)
{
    AnchorPane root;
    FXMLLoader loader=new FXMLLoader();
    ResourceBundle rb;
    
    Prompt=promptKey;
    Title=titleKey;
    try
    {
        loader.setLocation(getClass().getResource("/com/sc/colordx/resources/"));
        rb=ResourceBundle.getBundle("com.sc.colordx.resources.lang.Popup",application.getLocale());
       
        loader.setResources(rb);
        PopupController.prompt=Prompt;
        PopupController.title=Title;
        
        root = (AnchorPane)loader.load(getClass().getResource("/com/sc/colordx/presentation/Popup.fxml").openStream());
        getScene().setRoot(root);
        PopupController popupController=loader.getController();
        
        
            
        Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
        root.setPrefWidth(application.getStage().getWidth());
        root.setPrefHeight(application.getStage().getHeight());
        Node n=root.getChildren().get(0);
        n.setLayoutX(screenBounds.getWidth()/2.5);
        n.setLayoutY((screenBounds.getHeight()/2.5));
        //root.toFront();
        
        show(stage);

        
    } 
    catch (IOException ex) 
    {
        ex.printStackTrace();
    }
}


public static PopupDisplay getInstance()
{
    return instance;
}
@FXML
private void hide(MouseEvent event) 
{
    this.hide();
}
public void showInProgress()
{
    PopupController.showInProgress();
    
    
}

这是 Popup 的 FXML:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<AnchorPane id="AnchorPane" fx:id="anchorMain" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="768.0" prefWidth="1024.0" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="com.sc.colordx.controller.PopupController">
  <children>
    <GridPane id="GridPane" fx:id="gridMain" alignment="CENTER" layoutX="309.0" layoutY="330.0" minWidth="400.0" style="-fx-background-color:black;" styleClass="visibleWindow, gridpane, gridpane-boder" vgap="20.0">
      <children>
        <Label fx:id="lblPrompt" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="271.0" text="%keyPrompt" textFill="WHITE" textOverrun="CLIP" wrapText="true" GridPane.columnIndex="0" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER">
          <font>
            <Font name="System Bold" size="14.0" fx:id="x1" />
          </font>
          <GridPane.margin>
            <Insets bottom="6.0" left="6.0" right="6.0" top="6.0" />
          </GridPane.margin>
        </Label>
        <HBox id="HBox" fx:id="hboxButtons" alignment="CENTER" spacing="7.0" style="" styleClass="hbox" GridPane.columnIndex="0" GridPane.hgrow="ALWAYS" GridPane.rowIndex="2" GridPane.vgrow="ALWAYS">
          <children>
            <Button fx:id="btnOk" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onMouseClicked="#exitOkay" text="%keyYes" HBox.hgrow="ALWAYS" />
            <Button id="btnOk" fx:id="btnCancel" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onMouseClicked="#hide" text="%keyNo" HBox.hgrow="ALWAYS" />
          </children>
          <padding>
            <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
          </padding>
          <stylesheets>
            <URL value="@../resources/css/Popup.css" />
          </stylesheets>
        </HBox>
        <ProgressIndicator fx:id="progress" cache="true" cacheHint="QUALITY" progress="0.0" visible="false" GridPane.columnIndex="0" GridPane.rowIndex="1">
          <GridPane.margin>
            <Insets left="300.0" />
          </GridPane.margin>
        </ProgressIndicator>
      </children>
      <columnConstraints>
        <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
      </columnConstraints>
      <padding>
        <Insets />
      </padding>
      <rowConstraints>
        <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
       <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
        <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
      </rowConstraints>
        </GridPane>
      </children>
      <stylesheets>
        <URL value="@../resources/css/Popup.css" />
      </stylesheets>
</AnchorPane>

【问题讨论】:

    标签: linux windows macos popup javafx


    【解决方案1】:

    我在 MAC 中运行 JavaFx 应用程序时使用 Popup 得到了同样的结果,所以我所做的是使用 initStyle(StageStyle.UTILITY); 创建新阶段(高度和宽度 = 0 的虚拟/不可见)并将我的弹出窗口绑定。每次我需要显示弹出窗口时,我都会使用dummyStage.show();popup.toFront();,所以它会导致在 mac 中处理我的问题。

    【讨论】:

    • 是的,我知道解决方法。例如。我正在使用堆栈窗格并向其添加当前阶段根目录和弹出屏幕根目录以显示弹出窗口。但是我需要使用 Popup 本身的适当解决方案,因为我无法使用 FileChooser 应用解决方法。
    猜你喜欢
    • 2015-10-01
    • 1970-01-01
    • 2018-05-22
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-15
    相关资源
    最近更新 更多