我正在扩展javafx.stage.Popup来显示一个popup消息。 整个应用程序可以在Windows和Ubuntu上正常运行,但是在Mac上Popups会在应用程序全屏后进入当前阶段。 我试过使用z-index,.toFront(),设置所有者窗口和一切。 但popup窗口只是不显示! javafx.stage.FileChooser也是一样的问题。 由于应用程序必须始终处于全屏状态,因此解决scheme是什么?
编辑:在另一个页面,文本字段全屏闪烁但不接收键入的键! 而这只发生在全屏幕! 如果我失去全屏,文本字段接收键入的键。 很烦人:(请build议如果我应该提交一个错误或东西
我已经找出popup的解决方法,但问题仍然存在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>
我在使用Popup在Java中运行JavaFx应用程序的同样的事情,所以我用initStyle(StageStyle.UTILITY);
创建了新的Stage(虚拟/不可见,高度和宽度为0 initStyle(StageStyle.UTILITY);
并绑定我的弹出式。 每次我需要显示弹出我使用dummyStage.show();
和popup.toFront();
所以这将导致一个技巧来处理我的问题,在Mac中。