FXML 文件未打开

FXML File Not Opening

我正在尝试使用 Eclipse 使用 Scene Builder 打开 FXML 文件。我右键单击 fxml 文件并单击 'Open with SceneBuilder' 按钮。但是,场景生成器不会打开。然后我尝试创建一个新项目并创建一个新的fxml文件。 scenebuilder 打开新的 fxml 文件。我猜是文件本身出了问题。

这是我的 fxml 文件。

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

<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.effect.InnerShadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Line?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>

<AnchorPane minHeight="600.0" minWidth="900.0" prefHeight="600.0" prefWidth="900.0" style="-fx-background-color: black;" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainController">
   <children>
      <BorderPane prefHeight="600.0" prefWidth="900.0">
         <center>
            <Pane prefHeight="612.0" prefWidth="900.0" style="-fx-background-color: #0A1021;" BorderPane.alignment="CENTER">
               <children>
                  <ImageView fitHeight="607.0" fitWidth="660.0" layoutX="-201.0" layoutY="1.0" pickOnBounds="true" preserveRatio="true" style="-fx-opacity: 0.1;">
                     <image>
                        <Image url="@../img/login_background2.jpg" />
                     </image>
                  </ImageView>
                  <Button fx:id="login_button_1" layoutX="617.0" layoutY="327.0" lineSpacing="1.0" mnemonicParsing="false" onAction="#login_button1" prefHeight="55.0" prefWidth="126.0" text="LOGIN" textAlignment="CENTER" textFill="WHITE">
                     <font>
                        <Font name="Roboto Black" size="19.0" />
                     </font>
                     <cursor>
                        <Cursor fx:constant="HAND" />
                     </cursor>
                  </Button>
                  <ImageView fitHeight="216.0" fitWidth="230.0" layoutX="118.0" layoutY="114.0" pickOnBounds="true" preserveRatio="true">
                     <image>
                        <Image url="@../img/PCMS_logo.png" />
                     </image>
                  </ImageView>
                  <Text fill="WHITE" layoutX="125.0" layoutY="377.0" strokeType="OUTSIDE" strokeWidth="0.0" text="deFurtura">
                     <font>
                        <Font name="SansSerif Bold" size="46.0" />
                     </font>
                  </Text>
                  <Text fill="WHITE" layoutX="128.0" layoutY="402.0" strokeType="OUTSIDE" strokeWidth="0.0" text="beyond common furniture">
                     <font>
                        <Font name="SansSerif Bold Italic" size="17.0" />
                     </font>
                  </Text>
                  <Text fill="WHITE" layoutX="594.0" layoutY="251.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Hello!">
                     <font>
                        <Font name="Roboto" size="36.0" />
                     </font>
                  </Text>
                  <Text fill="WHITE" layoutX="594.0" layoutY="286.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Let's get started">
                     <font>
                        <Font name="Roboto" size="24.0" />
                     </font>
                  </Text>
                  <Button fx:id="exit_button" layoutX="870.0" layoutY="1.0" mnemonicParsing="false" onAction="#exit_button_action" prefHeight="20.0" prefWidth="20.0">
                     <graphic>
                        <FontAwesomeIconView fx:id="exit_icon" fill="WHITE" glyphName="TIMES_CIRCLE" size="18" />
                     </graphic>
                     <cursor>
                        <Cursor fx:constant="HAND" />
                     </cursor>
                  </Button>
               </children>
            </Pane>
         </center>
      </BorderPane>
      <Pane fx:id="login_pane" layoutX="932.0" layoutY="86.0" prefHeight="429.0" prefWidth="308.0" style="-fx-background-color: White; -fx-background-radius: 10; -fx-opacity: 1;">
         <children>
            <Text layoutX="104.0" layoutY="78.0" strokeType="OUTSIDE" strokeWidth="0.0" text="LOGIN">
               <font>
                  <Font name="Roboto Black" size="34.0" />
               </font>
            </Text>
            <Button fx:id="cancel_button" layoutX="264.0" layoutY="14.0" mnemonicParsing="false" onAction="#cancel_button_action" prefHeight="26.0" prefWidth="13.0">
               <graphic>
                  <FontAwesomeIconView fx:id="cancel_icon" fill="#aeaeae" glyphName="TIMES_CIRCLE" size="16" />
               </graphic>
               <cursor>
                  <Cursor fx:constant="HAND" />
               </cursor>
            </Button>
            <Line endX="135.0" layoutX="154.0" layoutY="101.0" startX="-135.0" />
            <VBox alignment="TOP_CENTER" layoutX="42.0" layoutY="115.0" prefHeight="289.0" prefWidth="229.0">
               <children>
                  <Label fx:id="login_label_status" prefHeight="54.0" prefWidth="208.0" style="-fx-border-style: solid; -fx-border-color: #e44040; -fx-border-width: 1; -fx-background-color: #FF7D7A; -fx-border-radius: 10; -fx-background-radius: 10;" text="Login Unsuccessful !&#10;The username or password is &#10;incorrect!" textFill="#e44040" visible="false">
                     <padding>
                        <Insets bottom="5.0" left="10.0" right="10.0" top="2.0" />
                     </padding>
                     <font>
                        <Font name="Roboto" size="13.0" />
                     </font>
                  </Label>
                  <Pane prefHeight="236.0" prefWidth="229.0">
                     <children>
                        <TextField fx:id="login_username" layoutX="11.0" layoutY="14.0" prefHeight="35.0" prefWidth="208.0" promptText=" Username">
                           <padding>
                              <Insets left="10.0" />
                           </padding>
                           <opaqueInsets>
                              <Insets />
                           </opaqueInsets>
                           <cursor>
                              <Cursor fx:constant="TEXT" />
                           </cursor>
                           <effect>
                              <InnerShadow height="3.21" radius="1.105" width="3.21" />
                           </effect>
                        </TextField>
                        <PasswordField fx:id="login_password" layoutX="11.0" layoutY="69.0" prefHeight="35.0" prefWidth="208.0" promptText=" Password" />
                        <Button fx:id="login_button_2" layoutX="47.0" layoutY="127.0" mnemonicParsing="false" onAction="#login_action" prefHeight="40.0" prefWidth="135.0" text="LOGIN" textFill="WHITE">
                           <font>
                              <Font name="Roboto Black" size="15.0" />
                           </font>
                           <cursor>
                              <Cursor fx:constant="HAND" />
                           </cursor>
                        </Button>
                        <FontAwesomeIconView fill="#bcb8b8" glyphName="USER" layoutX="196.0" layoutY="37.0" size="18" />
                        <FontAwesomeIconView fill="#bcb8b8" glyphName="UNLOCK_ALT" layoutX="196.0" layoutY="92.0" size="18" />
                     </children>
                  </Pane>
               </children>
            </VBox>
         </children>
         <effect>
            <DropShadow height="15.0" radius="7.0" width="15.0" />
         </effect>
      </Pane>
   </children>
</AnchorPane>

问题出在<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>。它不被认可。也许你可以试试这个How to use font awesome in a fxml project (javafx)

可能您使用的是场景生成器版本 11+,并且该特定版本不支持 font awesome。

您可以尝试卸载当前的场景构建器并安装场景构建器8.x

希望这能解决您的问题