0

So I've been following a tutorial for JavaFX and I used SceneBuilder to make a FXML view for my application. However, I can't seem to get anything to show up when I run the application - what am I doing wrong? I get no exceptions, adn the code compiles and runs fine. Here's my code.

import java.io.IOException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Driver extends Application {

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

    @Override
    public void start(Stage primaryStage) {

        FXMLLoader loader = new FXMLLoader(getClass().getResource("interface.fxml"));
        Pane root=null;

        try {
            root = (Pane) loader.load();
        }
        catch (IOException e) {
            e.printStackTrace();
        }

        Scene scene = new Scene(root);

        primaryStage.setTitle("Wiki Scraper");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}

Here is interace.fxml:

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

<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>


<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <Button layoutX="500.0" layoutY="351.0" mnemonicParsing="false" prefHeight="35.0" prefWidth="86.0" text="Scrape!" />
      <TextArea layoutX="185.0" layoutY="41.0" prefHeight="298.0" prefWidth="401.0" />
      <Label layoutX="350.0" layoutY="6.0" text="Console">
         <font>
            <Font size="24.0" />
         </font>
      </Label>
      <TextField layoutX="14.0" layoutY="41.0" />
      <Label layoutX="14.0" layoutY="24.0" text="URL to Start From" />
   </children>
</AnchorPane>
kibowki
  • 4,206
  • 16
  • 48
  • 74
  • Can you show us `interface.fxml`? Do you have any exception? Do you have an empty stage? – José Pereda Feb 18 '15 at 00:26
  • Thanks for your comment - I edited my question with the questions you asked. There were no exceptions. As for an empty stage, I'm not sure what you mean by that. How can I tell if I have an empty stage? – kibowki Feb 18 '15 at 00:28
  • It is working for me. I see a window with all the controls inside... How are you running this? – José Pereda Feb 18 '15 at 00:32
  • Using Spring Tool Suite (a variant of Eclipse), I select the Green play button in the top menu bar to run the application. – kibowki Feb 18 '15 at 00:32
  • Then you may have some problems there, I can't tell. Have a look at the Output window (console), you may have some warnings/errors there, that can provide some info about the problem. Using NetBeans I just created a new JavaFX project with your code, and it worked fine. – José Pereda Feb 18 '15 at 00:35
  • I just downloaded and created a test application in NetBeans and I also got it to show up there..must be some configuration in Eclipse that is off. – kibowki Feb 18 '15 at 00:53

0 Answers0