Hello world with JavaFX Fxml Project


Today i am Going to create Hello World Application with JavaFX Fxml project.Here is the code. Sample.fxml

<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml" fx:controller="temp.Temp">
    <Button id="button" layoutX="126" layoutY="90" text="Click Me!" onAction="#handleButtonAction" fx:id="button" />
    <Label id="label" layoutX="126" layoutY="120" minHeight="16" minWidth="69" prefHeight="16" prefWidth="69" fx:id="label" />


package temp;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
public class Sample implements Initializable {

private Label label;

private void handleButtonAction(ActionEvent event) {
    System.out.println("You clicked me!");
    label.setText("Hello World!");

public void initialize(URL url, ResourceBundle rb) {
    // TODO


package temp;
import javafx.application.Appl
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Temp extends Application {
public static void main(String[] args) {
    Application.launch(Temp.class, args);
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
    stage.setScene(new Scene(root));
    catch(Exception e){

But It is Giving Error /Users/apple/NetBeansProjects/Temp/nbproject/jfx-impl.xml:1757: The following error occurred while executing this line: /Users/apple/NetBeansProjects/Temp/nbproject/jfx-impl.xml:1392: jarsigner returned: 1 BUILD FAILED (total time: рем seconds)

But When i Use Exception Handling it Gives Location Not Found ? Please help

8/28/2012 6:29:09 AM

You are trying to load Controller from fx:controller="temp.Temp". This is not Your controller class, you should use fx:controller="temp.Sample" instead.

8/28/2012 8:58:43 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow