0

我的项目没有编译错误。但我的程序仍然打开并保持白色,而不是使用 css 文件。正如您在下面的代码示例中所见,我尝试手动添加样式表。

有人有想法吗?

设置 :

Java 8 SceneBuilder FontAwesomefx 8.9 jfoenix 8.0.1

主要类样本:

  FXMLLoader loader = new FXMLLoader();
        URL loc_login = Main.class.getResource("/fxml/loginscreen.fxml");
        loader.setLocation(loc_login);
        this.rootLayout = loader.load();
        Scene scene = new Scene(rootLayout);
        scene.getStylesheets().clear();
        scene.getStylesheets().add(getClass().getResource("/styles/dark-theme.css").toString());
        primaryStage.setScene(scene);
        primaryStage.centerOnScreen();
        primaryStage.show();

和 fxml 文件:

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

<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXPasswordField?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<AnchorPane styleClass="root" blendMode="SCREEN" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="400.0" stylesheets="@../styles/dark-theme.css" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <JFXPasswordField fx:id="password" focusColor="WHITE" layoutX="88.0" layoutY="148.0" prefHeight="26.0" prefWidth="250.0" promptText="Password" />
      <JFXTextField fx:id="username" focusColor="WHITE" layoutX="88.0" layoutY="95.0" prefHeight="26.0" prefWidth="250.0" promptText="Username" />
      <FontAwesomeIconView glyphName="LOCK" layoutX="62.0" layoutY="170.0" size="25" />
      <FontAwesomeIconView glyphName="USER" layoutX="62.0" layoutY="118.0" size="25" styleClass="glyph-icon" />
      <JFXButton layoutX="118.0" layoutY="217.0" prefHeight="30.0" prefWidth="84.0" text="S'inscrire" underline="true" />
      <JFXButton layoutX="215.0" layoutY="217.0" prefHeight="30.0" prefWidth="84.0" text="Login" underline="true" />
      <ImageView fitHeight="51.0" fitWidth="67.0" layoutX="99.0" layoutY="14.0">
         <image>
            <Image url="@../img/main-icon-penelope.png" />
         </image>
      </ImageView>
      <Label layoutX="160.0" layoutY="13.0" prefHeight="51.0" prefWidth="139.0" styleClass="app-label" text="MY PENELOPE F" textAlignment="CENTER" textFill="WHITE" />
   </children>
   <effect>
      <DropShadow />
   </effect>
   <cursor>
      <Cursor fx:constant="HAND" />
   </cursor>
</AnchorPane>
4

1 回答 1

0

我认为您需要fx:controller:<class name>在该行中添加您的 fxml 文件Anchorpane并替换<class name>为加载 fxml 的类的名称。

这应该有效。

于 2018-02-02T11:27:41.663 回答