Fundamentals‎ > ‎

A Simple JavaFX App


The listing below shows how to create a simple, yet functional JavaFX application that uses several components of the JavaFX application framework.  

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;

Stage {

    title: "JavaFX App"
    width: 300
    height: 200
    visible: true

    scene: Scene {

        fill:Color.SILVER
        width:320
        height:220

        content: [

            Rectangle {

                x: 100 y: 50
                width: 100 height: 100
                arcWidth: 10
                arcHeight: 10
                fill: Color.RED
            },

            Text {

                content: "JavaFX"
                x: 110 y: 60
                fill: Color.WHITE
                font: Font { size: 16 }
            }
        ]
    }

}


The figure below shows the application's parts when it is executed. The declarative script above arranges the content of the application as a hierarchical stack of Stage Scene Node, with Stage being the outer most container.



The materials on this website represent a small sample of content loosely based on the book JavaFX Application Development Cookbook.  The book offers far more content with over 80 recipes covering a range of topics from basics to advanced concepts.  

Buy the Book

You can get your copy of the book directly from the publisher. Click here to order!