
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 Background
In JavaFX, Background is a class that helps in setting the background of a selected region. Each background is formed of different fills or different background images which cannot be null but can be empty. As this class is immutable, the same Background can be used in several regions. Moreover, every BackgroundFill is rendered in an order, which is followed by its mentioned BackgroundImage. The outsets of background explain any extension of the Region’s drawing area which is essential to account for every background drawing.
Syntax:
// Background creation
Background bg = new Background(background_fill);
Here, bg is the object of background class.
Constructors
Let us see the constructors of the background class in JavaFX.
-
Background(BackgroundFill… f):
A new background object will be created with fills mentioned.
-
Background(BackgroundFill[] f, BackgroundImage[] im):
A new background object will be created with fills as well as the background images mentioned.
-
Background(BackgroundImage… i):
A new background object will be created with the background image mentioned.
-
Background(List f, List im):
A new background object will be created with a list of fills as well as a list of background images mentioned.
-
getFills()
A list of all background fills is returned.
-
getImages()
A list of all background images is returned.
-
getOutsets()
A list of all background outset is returned.
-
isEmpty()
This method checks whether the background is empty or not and returns the same.
-
isFillPercentageBased()
This method checks whether the background fill is based on percentages or not and returns the same.
Methods
Following are the commonly used methods of background class in JavaFX.
Examples of JavaFX Background
Now, it is time to see some sample programs on background class in JavaFX.
Example #1
// JavaFX program that demonstrates the working of background class.
Code:
import javafx.application.Application; import javafx.scene.Scene; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.canvas.*; import javafx.scene.web.*; import javafx.scene.layout.*; import javafx.scene.image.*; import java.io.*; import javafx.geometry.*; import javafx.scene.Group; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import javafx.scene.paint.*; //main class public class BackgroundClassProgram extends Application { // application launches here public void start(Stage st) { try { // set stage title st.setTitle("Background creation. . .") ; // label creation Label lb = new Label("user name : ") ; // text field creation TextFieldtf = new TextField(); // column count has to be set based on the requirement tf.setPrefColumnCount(10); // button creation Button bt = new Button("OK"); // add to hbox the created label lb, text field tf and button bt HBoxhb = new HBox(lb, tf, bt); // spacing set hb.setSpacing(10); // alignment settng for the HBox hb.setAlignment(Pos.CENTER); // scene creation Scene sc = new Scene(hb, 280, 280); // background fill creation BackgroundFill bf = new BackgroundFill(Color.RED, CornerRadii.EMPTY , Insets.EMPTY); //Background creation Background bg = new Background(bf); // set background hb.setBackground(bg); // scene setting st.setScene(sc); st.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } // Main Method public static void main(String args[]) { // launch the application launch(args); } }
Example #2
Code:
// JavaFX program that demonstrates the working of background class
import javafx.application.Application; import javafx.scene.Scene; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.canvas.*; import javafx.scene.web.*; import javafx.scene.layout.*; import javafx.scene.image.*; import java.io.*; import javafx.geometry.*; import javafx.scene.Group; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import javafx.scene.paint.*; //main class public class BackgroundClassProgram extends Application { // application launches here public void start(Stage st) { try { // set stage title st.setTitle("Background creation. . .") ; // label creation Label lb = new Label("user name : ") ; // text field creation TextFieldtf = new TextField(); // column count has to be set based on the requirement tf.setPrefColumnCount(10); // button creation Button bt = new Button("OK"); // add to hbox the created label lb, text field tf and button bt HBoxhb = new HBox(lb, tf, bt); //spacing set hb.setSpacing(10); // alignment setting for the HBox hb.setAlignment(Pos.CENTER); // scene creation Scene sc = new Scene(hb, 280, 280); // input stream creation FileInputStreaminp = new FileInputStream("d:\\eduCBA-logo1.png"); //image creation Image im = new Image(inp); // create a background image BackgroundImage bi = new BackgroundImage(im, BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.DEFAULT, BackgroundSize.DEFAULT); // Background creation Background bg = new Background(bi); // set background hb.setBackground(bg); // scene setting st.setScene(sc); st.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } // Main Method public static void main(String args[]) { // launch the application launch(args); } }
Example #3
// JavaFX program that demonstrates the working of background class.
Code:
import javafx.application.Application; import javafx.scene.Scene; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.canvas.*; import javafx.scene.web.*; import javafx.scene.layout.*; import javafx.scene.image.*; import java.io.*; import javafx.geometry.*; import javafx.scene.Group; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import javafx.scene.paint.*; import javafx.scene.shape.Circle; //main class public class BackgroundClassProgram extends Application { // application launches here public void start(Stage st) { try { // set stage title st.setTitle("Background creation. . .") ; // label creation Label lb = new Label("user name : ") ; //Draw a Circle Circle c = new Circle(); //Set the circle properties c.setCenterX(310.0f); c.setCenterY(125.0f); c.setRadius(110.0f); /// add circle HBoxhb = new HBox(c); // set spacing hb.setSpacing(10); // hbox alignment setting hb.setAlignment(Pos.CENTER); // scene creation Scene sc = new Scene(hb, 280, 280); // background fill creation BackgroundFill bf = new BackgroundFill(Color.RED, CornerRadii.EMPTY , Insets.EMPTY); // Background creation Background bg = new Background(bf); // set background hb.setBackground(bg); // scene setting st.setScene(sc); st.show(); } //catch the exception catch (Exception ec) { System.out.println(ec.getMessage()); } } // Main Method public static void main(String args[]) { // application launches here launch(args); } }
Apply now for Advanced Java Training Course