【问题标题】:FXML File Not OpeningFXML 文件未打开
【发布时间】:2020-02-25 15:48:42
【问题描述】:

我正在尝试使用 Eclipse 使用 Scene Builder 打开 FXML 文件。我右键单击 fxml 文件并单击“使用 SceneBuilder 打开”按钮。但是,场景构建器没有打开。然后我尝试创建一个新项目并创建一个新的 fxml 文档。场景构建器打开新的 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>

【问题讨论】:

  • 您的 FXML 文件中存在 Scene Builder 不知道的第三方库类。它可以在 Eclipse 中工作,因为 IDE 了解有关您项目的所有信息,包括您添加的依赖项。 Scene Builder 没有那么复杂。但是,您可以将库添加到 Scene Builder。打开“JAR/FXML 管理器”并添加库。
  • 这给出了一个将库添加到 Scene Builder 的示例:stackoverflow.com/questions/29601190/…

标签: java javafx scenebuilder


【解决方案1】:

问题出在&lt;?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?&gt;。它没有被识别。也许你可以试试这个How to use font awesome in a fxml project (javafx)

【讨论】:

    【解决方案2】:

    您可能正在使用 11+ 版本的场景构建器,并且该特定版本不支持 font awesome。

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

    希望这能解决您的问题?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-15
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多