
Quick Contact
Java Tutorial
- What is Java?
- History of Java
- Hello Java Program
- Features of Java
- Basic Syntax
- Java Setup
- Data Types in Java
- Java Variables
- Operators in Java
- JVM
- Java If-else Statement
- Switch Case Statement
- Java Loops
- Do-While Loop
- Java While Loop
- Continue Statement
- Break Statement in Java
- Constructors in Java
- Oops Concept in Java
- Features of OOPs
- Inheritance
- Exeception handeling
- Aggregation (HAS-A relationship) in Java
- Method Overriding in Java
- Method Overloading
- Java Static Keyword
- Java This Keyword
- Java Final Keyword
- Polymorphism
- Static Binding and Dynamic Binding
- Abstract class in Java
- Access Modifiers in Java
- Difference between abstract class and interface
- Interface in Java
- Garbage Collection in Java
- Java Package
- Encapsulation
- Serialization and Deserialization in Java
- Java Inner Classes
- Java Applets
- Multithreading in Java
- Thread Priorities in Java
- Thread Creation
- Inter Thread Communication
- Wrapper Classes in Java
- Java Input Output
- Java AWT Introduction
- Java Layout Manager
- Java Layout Policy
- Java AWT Events
- Collection Framework
- Collection Framework List Interface
- Swing in Java
- Swing Utility Classes
- Swing Layout Managers
- Java JDBC
- Hibernate Framework Overview – Architecture and Basics
Springboot
- Spring Environment Setup
- Spring Boot CRUD REST API Project using IntelliJ IDEA | Postman | MySQL
- Dockerizing Spring Boot Application | Spring Boot Docker Tutorial
- spring-boot-restapidocumentation with swagger
- Spring Boot HttpClient Overview
- Apache HttpClient POST HTTP Request Example
- Apache HttpClient PUT HTTP Request Example
- Apache HttpClient DELETE HTTP Request Example
- Apache HttpClient HTML Form POST Request Example
- Spring Boot JSP Exampl
- Deploying Spring Boot WAR file with JSP to Tomcat
- Spring Boot Annotations
- Spring Core Annotations
- Spring MVC Annotations with Examples
- Spring Scheduling Annotations
- Spring - Java-based Container Configuration
- Spring Java Based Configuration Example
Hibernate
- Hibernate 5 hello world
- Hibernate- One to One Unidirectional Mapping Annotation Example
- Hibernate - Batch Processing
- Hibernate - Interceptors
- Hibernate 5 - Create, Read, Update and Delete (CRUD) Operations Example
- Hibernate Transaction Management
- Hibernate One to Many Unidirectional Mapping Example
- Hibernate One to Many Bidirectional Mapping Example
- Hibernate Many to Many Annotation Mapping Example
- Hibernate Primary KeyJoin Column
- Hibernate First Level Cache with Example
- Hibernate XML Configuration Example with Maven + Eclipse + MySQL Database
- Hibernate Java Configuration Example
- JPA 2 with Hibernate 5 Bootstrapping Example
- JPA and Hibernate Cascade Types
- Hibernate/JPA - Primary Key Generation
- Hibernate 5 - Enum Type Mapping Example
- Hibernate Component Mapping
- Hibernate Object States – Transient,Persistent and Detached
- Hibernate 5 - Save an Entity Example
- Hibernate 5 - Persist an Entity Example
- Hibernate 5 - saveOrUpdate() Method Example
- Hibernate 5 - get(), load() and byId() Method Examples
- Hibernate 5 - merge() Example
- Hibernate 5 - Delete or Remove an Entity Example
- Hibernate 5 - load() Method Example
- Hibernate Session Interface Methods
- Hibernate Session.clear() Method Example
- Introduction Of Java strutes to Architecture
- Struts 2 - Architecture
- Struts 2 - Configuration Files
- Struts 2 - Actions
- Struts 2 - Interceptors
- Struts 2 - Results & Result Types
- Struts 2 - Value Stack/OGNL
- Struts 2 - File Uploading
- Struts 2 - Database Access
- Struts 2 - Validations Framework
JAVA FX
- JavaFX Tutorial
- Introduction to JavaFX Pane
- JavaFX Popup
- JavaFX group
- JavaFX Controller
- JavaFX Gradient Color
- JavaFXAnchorPane
- JavaFXTabPane
- JavaFX Scene
- JavaFX Stage
- JavaFXWebView
- JavaFX Timeline
- JavaFX Timer
- JavaFX Image
- JavaFX Background
- JavaFX dialog
- JavaFX Font
- JavaFXTextArea
- JavaFXObservableList
- JavaFX GUI
- JavaFX FXML
- JavaFXEventHandler
- JavaFXGradle
- JavafxScrollpane
- JavaFXAPI
JavaFX Stage
The JavaFX Stage is a desktop screen which displays JavaFX output to the user, also it is said that Stage is window. Inside a JavaFX Stage we are inserting a JavaFX element Scene which displays the content inside the window or we can say inside a Stage. When main method called from an application inside launch() method calls automatically start(). This start method has one argument that is Stage object, which creates primary stage object.
This primary stage object creates a window to display user created functionality in the output. If your requirement is more than one stage then we can create as many Stage objects as we want. JavaFX Stage class available in javafx.stage.Stagepackage. So if we want to make use of Stage then we must import this package. It displays the output to the end user from a stage window.
Constructors
Given below are the constructors:
-
Stage():
This Stage() constructor create a instance by new keyword without any arguments.
-
Stage(Node n):
This Stage() constructor create a instance by new keyword with any JavaFX element as argument.
Frequently used Methods
Given below are the frequently used methods:
-
show():
The show() method will show the output.
-
setScene(scene):
The setScene() method set the Scene object.
-
setTitle():
The setTitle() sets the title of the application.
-
setX(int value):
The setX() method sets the position of the upper left corner of the application.
-
setY(int value):
The setY() method sets the position of the upper left corner of the application.
-
setWidth(int width):
The setWidth() method sets the width of stage window.
-
setHeight(int height):
The setHeight() method sets the height of stage window.
-
showAndWait():
The showAndWait() method will show the output but object will be still alive until stage is closed.
-
initModality():
The initModality must be done before making the stage visible.
-
None:
It is a default value.
-
WINDOW_MODAL:
This value makes stage that blocks input events from all of windows from its owner and to its root object.
-
APPLICATION_MODAL:
This value makes stage that blocks input events from all of windows from the same application.
-
initOwner():
The initOwner() method sets the owner of the application.
-
initStyle():
The initStyle() method sets the style of the stage window.
It has below constant values:
It has below constant values:
-
Undecorated:
This value gives without any decoration means white background.
-
Transparent:
This value gives transparent background.
-
Unified:
This value is not given any border between decoration area and main content area.
-
Utility:
This value gives you minimal decorations.
How does Stage work in JavaFX?
- Accessing JavaFX features user defined class must extendsApplication class.
- In JavaFX creating any JavaFX element is first step. ImageView, AnchorePane, ScrollPane, MenuBar etc.
- This can instantiate by using new keyword.
Syntax:
ImageViewimageView=new ImageView(); ScrollPanescrollPane=new ScrollPane(); AnchorPaneanchorPaneRef=new AnchorPane (); . . Etc.
Syntax:
VBoxvBox=new VBox (scrollPane or ImageView ,anchorPaneRef etc.); //Gives vertical box
Syntax:
Scene screen = new Scene(vBox, length, width);
Syntax:
stage.setScene(screen);
Syntax:
stage.show();
Examples of JavaFX Stage
Given below are the examples:
Example #1
Code:
package com.stage; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; public class StageDemo extends Application { @Override public void start(Stage outStage) throws Exception { // setting the title for our application outStage.setTitle("Stage Demo"); // creating a group object for adding it to the scene Group group = new Group(); // creating a scene object with width and height Scene sceneOut = new Scene(group, 520, 520); // setting AQUA color to the scene object sceneOut.setFill(Color.AQUA); // Adding scene object to the stage object outStage.setScene(sceneOut); // showing the output to the user outStage.show(); } public static void main(String args[]) { // JVM calls start method automatically launch(args); } }
Example #2
Code:
package com.stage; import javafx.application.Application; import javafx.stage.Modality; import javafx.stage.Stage; public class ModalityDemo extends Application { @Override public void start(Stage primaryStage) { // Adding a tile to the application primaryStage.setTitle("Modality Demo"); //Creating another stage other than primary default stage Stagestage = new Stage(); stage.setTitle("Secondary Stage"); //Set the width and height of the other stage window stage.setWidth(400); stage.setHeight(400); //setting modality to APPLICATION_MODAL stage.initModality(Modality.APPLICATION_MODAL); // stage.initModality(Modality.WINDOW_MODAL); // stage.initModality(Modality.NONE); //Set the width and height of the primary stage window primaryStage.setWidth(500); primaryStage.setHeight(500); //It will show the output primaryStage.show(); //It will show the output until stage object closed stage.showAndWait(); } public static void main(String args[]) { // JVM calls start method automatically launch(args); } }
Example #3
Stage style with Label.
Code:
package com.stage; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.VBox; import javafx.stage.Modality; import javafx.stage.Stage; import javafx.stage.StageStyle; public class StageStyleDemo extends Application { @Override public void start(Stage primaryStage) { // Adding a tile to the application primaryStage.setTitle("Stage Style Demo"); // It applies the styles to window // stage.initStyle(StageStyle.UNDECORATED); // stage.initStyle(StageStyle.TRANSPARENT); primaryStage.initStyle(StageStyle.UNIFIED); // stage.initStyle(StageStyle.UTILITY); // creating a label object Label label = new Label("\n\n\t\t\tHello, Hi I am Stage Demo Content"); // creating vbox object VBoxvBox = new VBox(label); // creating a scene object Scene scene = new Scene(vBox,400,400); primaryStage.setScene(scene); // It will show the output primaryStage.show(); } public static void main(String args[]) { // JVM calls start method automatically launch(args); } }
Apply now for Advanced Java Training Course