2016-07-23 131 views
0

我已經通過eclipse使用場景生成器構建了一個GUI。JavaFX fxml沒有啓動/做任何事

我試圖運行MainApp類來查看eclipse中的GUI,一切都編譯,控制檯中沒有錯誤消息,java進程打開但實際沒有發生任何事情,並且在屏幕上沒有創建窗口。

我已經通過oracle的網站,並試圖改變代碼,但沒有任何工作。我已經更新了java,在eclipse中重新安裝了javafx等。我也試圖通過netbeans程序來達到同樣的效果。

運行在Mac OS X

package main; 

import java.util.logging.Level; 
import java.util.logging.Logger; 
import javafx.application.Application; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.scene.layout.StackPane; 
import javafx.stage.Stage; 

public class MainApp extends Application { 

/** 
* @param args the command line arguments 
*/ 
public static void main(String[] args) { 
    Application.launch(MainApp.class, (java.lang.String[])null); 
} 

@Override 
public void start(Stage primaryStage) { 
    try { 
     Parent root = FXMLLoader.load(getClass().getResource("GUI.fxml")); 

     Scene scene = new Scene(root); 

     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } catch (Exception ex) { 
     Logger.getLogger(MainApp.class.getName()).log(Level.SEVERE, null, ex); 
    } 
} 
`package main; 

控制器類

public class Controller implements Initializable { 

@FXML 
Button checkButton; 
@FXML 
Button callButton; 
@FXML 
Button raiseButton; 
@FXML 
Button foldButton; 


public void buttonClicked() { 
    System.out.println("Button was clicked"); 
} 

@Override 
public void initialize(URL location, ResourceBundle resources) { 
    // TODO Auto-generated method stub 

} 
} 
} 

的FXML文件

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


<?import javafx.scene.chart.CategoryAxis?> 
<?import javafx.scene.chart.LineChart?> 
<?import javafx.scene.chart.NumberAxis?> 
<?import javafx.scene.control.Button?> 
<?import javafx.scene.control.ButtonBar?> 
<?import javafx.scene.control.Label?> 
<?import javafx.scene.control.SplitPane?> 
<?import javafx.scene.control.TextArea?> 
<?import javafx.scene.image.Image?> 
<?import javafx.scene.image.ImageView?> 
<?import javafx.scene.layout.AnchorPane?> 

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="800.0" style="-fx-background-color: #FFFFFF;" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="main.Controller"> 
    <children> 
     <SplitPane dividerPositions="0.29949874686716793" layoutX="123.0" layoutY="67.0" prefHeight="433.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="67.0"> 
     <items> 
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> 
       <children> 
        <LineChart layoutY="206.0" prefHeight="215.0" prefWidth="235.0"> 
        <xAxis> 
         <CategoryAxis side="BOTTOM" /> 
        </xAxis> 
        <yAxis> 
         <NumberAxis side="LEFT" /> 
        </yAxis> 
        </LineChart> 
        <LineChart prefHeight="215.0" prefWidth="235.0"> 
        <xAxis> 
         <CategoryAxis side="BOTTOM" /> 
        </xAxis> 
        <yAxis> 
         <NumberAxis side="LEFT" /> 
        </yAxis> 
        </LineChart> 
       </children> 
      </AnchorPane> 
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> 
       <children> 
        <SplitPane dividerPositions="0.6783216783216783" orientation="VERTICAL" prefHeight="498.0" prefWidth="555.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> 
        <items> 
         <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" /> 
         <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="127.0" prefWidth="553.0"> 
          <children> 
           <TextArea disable="true" layoutX="9.0" layoutY="23.0" prefHeight="106.0" prefWidth="536.0" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="9.0" AnchorPane.rightAnchor="8.0" AnchorPane.topAnchor="23.0" /> 
           <Label layoutX="14.0" layoutY="6.0" text="Live guidance:" /> 
          </children> 
         </AnchorPane> 
        </items> 
        </SplitPane> 
       </children> 
      </AnchorPane> 
     </items> 
     </SplitPane> 
     <ImageView fitHeight="62.0" fitWidth="200.0" layoutX="14.0" layoutY="5.0"> 
     <image> 
      <Image url="@../../../../../Desktop/Dissertation%20files/logo.jpg" /> 
     </image> 
     </ImageView> 
     <ButtonBar layoutX="456.0" layoutY="16.0" prefHeight="40.0" prefWidth="200.0"> 
     <buttons> 
      <Button fx:id="checkButton" mnemonicParsing="false" onAction="#buttonClicked" onMouseClicked="#buttonClicked" style="-fx-background-radius: 10;" text="Check" /> 
      <Button fx:id="callButon" mnemonicParsing="false" onAction="#buttonClicked" onMouseClicked="#buttonClicked" style="-fx-background-radius: 10;" text="Call" /> 
      <Button fx:id="raiseButton" mnemonicParsing="false" onAction="#buttonClicked" onMouseClicked="#buttonClicked" prefHeight="27.0" prefWidth="81.0" style="-fx-background-radius: 10;" text="Raise" /> 
      <Button fx:id="foldButton" mnemonicParsing="false" onAction="#buttonClicked" onMouseClicked="#buttonClicked" style="-fx-background-radius: 10;" text="Fold" /> 
     </buttons> 
     </ButtonBar> 
    </children> 
</AnchorPane> 

道歉,如果我失去了一些東西簡單。

+0

它工作正常,我。 (我假設'MainApp'中缺少'}','Controller'中的''''只是複製和粘貼錯誤。) –

+0

您的GUI.fxml文件位於何處?在文件夾或包內,或在目錄的根目錄? – NwDev

+0

@James_D是道歉,第一次真的使用stackoverflow,所以我的壞。 – OliverJohnson

回答

0

如果類和FXML文件是相同的包下再裝載機線應該是這樣的

Parent root = FXMLLoader.load(getClass().getResource("/package_name/fxml2GUI.fxml")); 

在「包名」的地方把你的源的包名