Popup仅在Mac上落后于舞台,但在全屏幕上不在Windows / Linux上

时间:2013-12-18 11:41:16

标签: linux windows macos popup javafx

我正在扩展javafx.stage.Popup以显示弹出消息。整个应用程序在Windows和Ubuntu上运行良好,但在Mac Popups上,当应用程序全屏时,在当前阶段后面。我尝试过使用z-index,.toFront(),设置所有者窗口等等。但弹出窗口从未出现过!同样的问题是javafx.stage.FileChooser。由于应用必须始终全屏,解决方案是什么?

编辑:在另一个页面中,文本字段的光标全屏闪烁,但未收到键入的键!全屏幕出现 ONLY !如果我丢失全屏,则文本字段会收到键入的键。相当讨厌:(请建议我是否应该提交错误或其他内容

我已经找到弹出窗口的解决方法,但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>

1 个答案:

答案 0 :(得分:1)

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