簡體   English   中英

JavaFX無法加載FXML

[英]JavaFX Trouble Loading FXML

我在將FXML文件登錄名輸入JavaFX應用程序時遇到問題。

有人可以告訴我我在做什么錯嗎?

我對Swing的JavaFX非常陌生,所以請原諒,如果它確實不好或不正確的話。

package application;

import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;


public class Main extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        try {
            AnchorPane page = (AnchorPane) FXMLLoader.load(getClass().getResource("application/MainDisplay.fxml"));
            Scene scene = new Scene(page);
            primaryStage.setScene(scene);
            primaryStage.setTitle("Welcome!");
            primaryStage.show();
        } 
        catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

        }
    }
}

這是fXML文件

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

<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>


<AnchorPane prefHeight="400.0" prefWidth="600.0"     xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.65">
   <children>
      <Text layoutX="177.0" layoutY="137.0" strokeType="OUTSIDE"     strokeWidth="0.0" text="Welcome!" wrappingWidth="140.02001953125">
         <font>
            <Font size="25.0" />
         </font>
         <cursor>
            <Cursor fx:constant="NONE" />
         </cursor>
      </Text>
      <Text layoutX="177.0" layoutY="179.0" strokeType="OUTSIDE"     strokeWidth="0.0" text="User Name:" wrappingWidth="85.9443359375" />
      <Text layoutX="177.0" layoutY="213.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Password:" />
      <Button layoutX="353.0" layoutY="242.0" mnemonicParsing="false" text="Sign In" />
      <TextField layoutX="263.0" layoutY="161.0" />
      <PasswordField layoutX="263.0" layoutY="195.0" />
   </children>
</AnchorPane>

嘗試這個:

@Override
    public void start(Stage primaryStage){
        try {
            AnchorPane page = (AnchorPane) FXMLLoader.load(getClass().getResource("/application/MainDisplay.fxml"));
            Scene scene = new Scene(page);
            primaryStage.setScene(scene);
            primaryStage.setTitle("Welcome!");
            primaryStage.show();
        } 
        catch (Exception e) {
            e.printStackTrace();
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM