Structure of JavaFX application
Every JavaFX application's main Class extends the Application Class and Override the start(Stage stage) Method. Start Method is entry point of Application. Stage is the the top most container which contains UI components, whether it is deployed on desktop,within a browser, or other Devices.
Stage class has set of properties and methods.
1.) A Scene - It contains the graphical nodes in the user interface.
2.) A title - appears in the title bar of the window(when deployed on the desktop).
3.)Width, Hight, X, Y, Opacity, fullScreen etc.
Stage class has set of properties and methods.
1.) A Scene - It contains the graphical nodes in the user interface.
2.) A title - appears in the title bar of the window(when deployed on the desktop).
3.)Width, Hight, X, Y, Opacity, fullScreen etc.
Using Stage Class
Add following method calls in your application ....
public void start(Stage stage) throws Exception { Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml")); //load the ui from fxml file Scene scene = new Scene(root); //A scene container stage.setScene(scene); //add the scene to stage stage.setTitle("My First JavaFX App"); //set the title of stage stage.setWidth(500); //width of stage stage.setHeight(500); //height of stage stage.setOpacity(.8); //Transparency of stage 0 for fully transparent 1 for no transparency. stage.show(); }
Next:- JavaFx : Tutorial Series - part 3
No comments:
Post a Comment