加载后的Java fx意外镜像效果

时间:2018-07-27 13:36:11

标签: java javafx

在更改我的fxml结构时遇到了镜面反射效果。

您可以看到它here

我这样加载代码

设置场景

loader.setLocation(this.getClass().getResource("/gui/fxml/MainMain.fxml"));
    mainLayout = loader.load();

    Scene scene = new Scene(mainLayout);

    primaryStage.setScene(scene);


    primaryStage.show();

这将加载此fxml

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

<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>

<BorderPane fx:id="mainBorderPane" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Gui.fxml.MainMainViewController">
   <bottom>
      <HBox prefHeight="30.0" prefWidth="200.0" BorderPane.alignment="CENTER">
         <children>
            <Button fx:id="changeView" alignment="BOTTOM_LEFT" contentDisplay="BOTTOM" mnemonicParsing="false" text="Switch view" />
         </children>
      </HBox>
   </bottom>
</BorderPane>

然后在此fxml的控制器中执行此操作

@Override
public void initialize(URL location, ResourceBundle resources) {
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(this.getClass().getResource("MainView.fxml"));
    try {
        mainBorderPane.setCenter(loader.load());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

加载旧的主要fxml

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

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.CheckMenuItem?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.effect.Reflection?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="700.0" prefWidth="1250.0" stylesheets="@../../../resources/MyCustomCss.css" xmlns="http://javafx.com/javafx/8.0.152" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Gui.fxml.MainViewController">
   <top>
      <BorderPane prefHeight="35.0" prefWidth="200.0" BorderPane.alignment="CENTER">
         <center>
            <MenuBar fx:id="menuBar" BorderPane.alignment="CENTER">
              <menus>
                <Menu mnemonicParsing="false" text="File">
                  <items>
                        <Menu mnemonicParsing="false" text="Options">
                          <items>
                              <CheckMenuItem fx:id="clipBoard" mnemonicParsing="false" onAction="#setSaveToClipBoard" text="Save to Clipboard" />
                            <MenuItem fx:id="columnColors" mnemonicParsing="false" onAction="#openSettingsPane" text="Set colors" />
                          </items>
                        </Menu>
                  </items>
                </Menu>
              </menus>
            </MenuBar>
         </center>
         <right>
            <TextField fx:id="TextField" onKeyTyped="#sort" prefHeight="31.0" prefWidth="191.0" BorderPane.alignment="CENTER" />
         </right>
      </BorderPane>
   </top>
   <left>
      <TableView fx:id="tableView" onKeyReleased="#mouseSetRightSideInfo" onMouseClicked="#mouseSetRightSideInfo" prefHeight="664.0" prefWidth="703.0" tableMenuButtonVisible="false" BorderPane.alignment="CENTER">
        <columns>
          <TableColumn fx:id="id" editable="false" prefWidth="33.0" resizable="false" sortable="false" text="#" />
            <TableColumn fx:id="ip" prefWidth="168.0" text="IP" />
            <TableColumn fx:id="name" prefWidth="155.0" text="Name" />
          <TableColumn fx:id="type" prefWidth="185.0" text="Type" />
            <TableColumn fx:id="date" minWidth="-1.0" prefWidth="156.0" text="Next Update" />
        </columns>
         <effect>
            <Reflection />
         </effect>
      </TableView>
   </left>
   <right>
      <Pane fx:id="pane" prefHeight="665.0" prefWidth="416.0" BorderPane.alignment="CENTER">
         <children>
            <GridPane fx:id="mainGrid" alignment="TOP_CENTER" layoutX="-100.0" layoutY="-9.0" nodeOrientation="LEFT_TO_RIGHT" prefHeight="503.0" prefWidth="510.0">
              <columnConstraints>
                <ColumnConstraints halignment="LEFT" hgrow="SOMETIMES" maxWidth="159.0" minWidth="10.0" prefWidth="116.0" />
                <ColumnConstraints halignment="LEFT" hgrow="SOMETIMES" maxWidth="398.0" minWidth="10.0" prefWidth="394.0" />
              </columnConstraints>
              <rowConstraints>
                  <RowConstraints maxHeight="236.0" minHeight="10.0" prefHeight="25.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="236.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="183.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="398.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="398.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="398.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
                <RowConstraints maxHeight="398.0" minHeight="0.0" prefHeight="80.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="236.0" minHeight="10.0" prefHeight="80.0" vgrow="SOMETIMES" />
                <RowConstraints maxHeight="220.0" minHeight="0.0" prefHeight="80.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="274.0" minHeight="0.0" prefHeight="80.0" vgrow="SOMETIMES" />
                  <RowConstraints maxHeight="274.0" minHeight="0.0" prefHeight="80.0" vgrow="SOMETIMES" />
              </rowConstraints>
               <children>
                  <Label prefHeight="46.0" prefWidth="92.0" text="Data:" GridPane.rowIndex="2" />
                  <DatePicker fx:id="datepicker" prefHeight="31.0" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
                  <Label prefHeight="45.0" prefWidth="55.0" text="Logi -&gt;" wrapText="true" GridPane.rowIndex="6" />
                  <Button fx:id="link" mnemonicParsing="false" onMouseClicked="#showLogs" prefHeight="31.0" prefWidth="150.0" text="Open" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowIndex="6" GridPane.valignment="CENTER">
                     <GridPane.margin>
                        <Insets />
                     </GridPane.margin>
                  </Button>
                  <Label text="StartTime" GridPane.rowIndex="7" />
                  <Label text="EndTime" GridPane.rowIndex="8" />
                  <ComboBox fx:id="StartTime" prefHeight="31.0" prefWidth="150.0" promptText="StartTime" GridPane.columnIndex="1" GridPane.rowIndex="7" />
                  <ComboBox fx:id="EndTime" prefHeight="31.0" prefWidth="150.0" promptText="EndTime" GridPane.columnIndex="1" GridPane.rowIndex="8" />
                  <Label prefHeight="63.0" prefWidth="66.0" text="Update" GridPane.rowIndex="10" />
                  <Label prefHeight="57.0" prefWidth="82.0" text="Send Email" GridPane.rowIndex="9" />
                  <GridPane GridPane.columnIndex="1" GridPane.rowIndex="9">
                    <columnConstraints>
                      <ColumnConstraints hgrow="SOMETIMES" maxWidth="190.0" minWidth="10.0" prefWidth="87.0" />
                        <ColumnConstraints hgrow="SOMETIMES" maxWidth="290.0" minWidth="2.0" prefWidth="261.0" />
                    </columnConstraints>
                    <rowConstraints>
                      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                    </rowConstraints>
                     <children>
                        <CheckBox fx:id="emailReschedule" mnemonicParsing="false" onMouseClicked="#saveRescheduleEmail" prefHeight="21.0" prefWidth="200.0" text="Set auto rescheduling" GridPane.columnIndex="1" />
                        <CheckBox fx:id="sendEmialCheckBox" mnemonicParsing="false" onMouseClicked="#sendEmail" prefHeight="21.0" prefWidth="74.0" text="Send" />
                     </children>
                  </GridPane>
                  <GridPane alignment="BOTTOM_LEFT" prefHeight="50.0" prefWidth="202.0" GridPane.columnIndex="1" GridPane.rowIndex="10">
                    <columnConstraints>
                      <ColumnConstraints hgrow="SOMETIMES" maxWidth="192.0" minWidth="0.0" prefWidth="54.0" />
                      <ColumnConstraints hgrow="SOMETIMES" maxWidth="282.0" minWidth="0.0" prefWidth="228.0" />
                    </columnConstraints>
                    <rowConstraints>
                      <RowConstraints />
                      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                    </rowConstraints>
                     <children>
                        <CheckBox fx:id="updateReschedule" alignment="BOTTOM_LEFT" mnemonicParsing="false" onMouseClicked="#saveRescheduleEmail" prefHeight="21.0" prefWidth="207.0" text="Set auto rescheduling" GridPane.columnIndex="1" GridPane.rowIndex="1" />
                        <CheckBox fx:id="doUpdate" alignment="BOTTOM_LEFT" mnemonicParsing="false" onMouseClicked="#saveUpdateValue" prefHeight="21.0" prefWidth="166.0" text="Update" GridPane.rowIndex="1" />
                     </children>
                  </GridPane>
                  <Label text="Właściciel" GridPane.rowIndex="1" />
                  <Label text="Typ serwera" GridPane.rowIndex="5" />
                  <Label text="Tydzień miesiąca" GridPane.rowIndex="3" />
                  <Label text="Dzień tygodnia" GridPane.rowIndex="4" />
                  <Label fx:id="owner" onMouseClicked="#changeOwner" prefHeight="35.0" prefWidth="247.0" text="Owner" GridPane.columnIndex="1" GridPane.rowIndex="1" />
                  <ComboBox fx:id="boxWeekOfMonth" prefWidth="150.0" promptText="Tydzień" GridPane.columnIndex="1" GridPane.rowIndex="3" />
                  <ComboBox fx:id="boxServerType" prefWidth="150.0" promptText="Typ" GridPane.columnIndex="1" GridPane.rowIndex="5" />
                  <ComboBox fx:id="boxDayOfWeek" prefWidth="150.0" promptText="Dzień" GridPane.columnIndex="1" GridPane.rowIndex="4" />
               </children>
            </GridPane>
            <GridPane layoutX="-100.0" layoutY="499.0" prefHeight="152.0" prefWidth="512.0">
              <columnConstraints>
                <ColumnConstraints hgrow="SOMETIMES" maxWidth="248.0" minWidth="10.0" prefWidth="68.0" />
                <ColumnConstraints hgrow="SOMETIMES" maxWidth="444.0" minWidth="10.0" prefWidth="444.0" />
              </columnConstraints>
              <rowConstraints>
                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
              </rowConstraints>
               <children>
                  <Label alignment="TOP_LEFT" text="Uwagi" />
                  <TextArea fx:id="uwagi" onKeyPressed="#noteChange" prefHeight="152.0" prefWidth="128.0" wrapText="true" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.valignment="CENTER">
                     <GridPane.margin>
                        <Insets right="12.0" />
                     </GridPane.margin>
                  </TextArea>
               </children>
            </GridPane>
         </children>
      </Pane>
   </right>
</BorderPane>

为什么会得到这种怪异的镜面效果?为什么在BorderPain底部空间的BorderPain中心布局中设置了什么?

0 个答案:

没有答案