fxml file not behaving as expected in OS X

扶醉桌前 提交于 2019-12-25 06:47:52

问题


I am using an fxml file to to create my java fx UI. the file is:-

<?import java.lang.String?>
<?import javafx.collections.FXCollections?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>

<AnchorPane fx:id="ap" maxHeight="1.7976931348623157E308"
    maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity"
    prefHeight="480.0" prefWidth="840.0" xmlns="http://javafx.com/javafx/8.0.65"
    xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.Buildsapp.Main.BuildsController">
    <children>
        <VBox prefHeight="200.0" prefWidth="100.0"
            AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
            AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
            <children>
                <HBox alignment="CENTER_LEFT" spacing="20.0" VBox.vgrow="NEVER">
                    <padding>
                        <Insets bottom="12.0" left="12.0" right="12.0" top="12.0" />
                    </padding>
                    <children>
                        <GridPane hgap="10.0" HBox.hgrow="NEVER">
                            <columnConstraints>
                                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
                                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
                                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
                                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
                                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
                                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
                                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
                            </columnConstraints>
                            <rowConstraints>
                                <RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
                                <RowConstraints minHeight="10.0" prefHeight="30.0"
                                    vgrow="SOMETIMES" />
                            </rowConstraints>
                            <children>
                                <Label prefHeight="21.0" prefWidth="88.0" text="Platform" />
                                <ComboBox fx:id="versionCombo" prefHeight="31.0"
                                    prefWidth="108.0" GridPane.rowIndex="1">
                                    <items>
                                        <FXCollections fx:factory="observableArrayList">
                                            <String fx:value="Win" />
                                            <String fx:value="Mac" />
                                        </FXCollections>
                                    </items>
                                    <value>
                                        <String fx:value="Mac" />
                                    </value>
                                </ComboBox>
                                <Label prefHeight="21.0" prefWidth="80.0" text="Product"
                                    GridPane.columnIndex="1" />
                                <ComboBox fx:id="verCombo" prefHeight="31.0" prefWidth="127.0"
                                    promptText="build" GridPane.columnIndex="1" GridPane.rowIndex="1">
                                    <items>
                                        <FXCollections fx:factory="observableArrayList">
                                            <String fx:value="build" />
                                            <String fx:value="build2" />
                                        </FXCollections>
                                    </items>

                                </ComboBox>
                                <Label text="Version" GridPane.columnIndex="2" />
                                <ComboBox fx:id="versionNo" prefHeight="31.0"
                                    prefWidth="109.0" GridPane.columnIndex="2" GridPane.rowIndex="1" />
                                <Label prefHeight="21.0" prefWidth="60.0" text="Server"
                                    GridPane.columnIndex="3" />
                                <ComboBox fx:id="locCombo" prefHeight="31.0" prefWidth="103.0"
                                    GridPane.columnIndex="3" GridPane.rowIndex="1">
                                    <items>
                                        <FXCollections fx:factory="observableArrayList">
                                            <String fx:value="SJ" />
                                            <String fx:value="MN" />
                                        </FXCollections>
                                    </items>
                                    <value>
                                        <String fx:value="SJ" />
                                    </value>
                                </ComboBox>
                                <Button fx:id="downloadButton" minWidth="80.0"
                                    mnemonicParsing="false" text="Download" GridPane.columnIndex="4"
                                    GridPane.rowIndex="1" />
                                <Button fx:id="installButton" minWidth="80.0"
                                    mnemonicParsing="false" text="Install" GridPane.columnIndex="5"
                                    GridPane.rowIndex="1" />
                                <Button fx:id="locButton" mnemonicParsing="false"
                                    prefHeight="31.0" prefWidth="120.0" text="Open Folder"
                                    GridPane.columnIndex="6" GridPane.rowIndex="1" />
                            </children>
                        </GridPane>
                    </children>
                </HBox>
                <TableView fx:id="tableView" VBox.vgrow="ALWAYS">
                    <columns>
                        <TableColumn fx:id="builds" prefWidth="482.0" text="Builds" />
                        <TableColumn fx:id="date" minWidth="0.0" prefWidth="500.0"
                            text="Date" />
                    </columns>
                </TableView>
            </children>
        </VBox>

    </children>
</AnchorPane>

It works fine in windows while in mac when I launch the app the app window does not appear as expected but it appears as a small window on the top left corner.

The similar issue is appearing with the progress dialog which I am using it works fine in Windows but in mac(OS X) when the app is expanded like when app window size is maximum the progress dialog is also covering the whole display screen while I have given fixed size to scene window.

This is my progress bar code:-

public ProgressBar startProgressBar() {
        primaryStage = new Stage();
        ProgressBar pb = new ProgressBar(0);
        //ProgressIndicator pi = new ProgressIndicator(0);
        //pi.progressProperty().bind(pb.progressProperty());
        HBox hb = new HBox();
        hb.setSpacing(5);
        hb.setAlignment(Pos.CENTER);
        hb.getChildren().addAll(pb);
        Scene scene = new Scene(hb, 300, 100);
        primaryStage.setScene(scene);
        primaryStage.setTitle("Downloading Build...");
        primaryStage.show();
        return pb;
    }

回答1:


I am able find the solution for the first issue that can be solved my fixing the minHight and minWidth of the anchor panel to some value in fxml file instead of infinity but I am still not able to find the solution for the second issue.



来源:https://stackoverflow.com/questions/37108836/fxml-file-not-behaving-as-expected-in-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!