
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 Font
In JavaFX, font is a class that is used to denote fonts that renders the text available on screen. It is inherited from the object class.Font size is explained as mentioned in the points that are real-world measurementroughly 1/72 inch.Fonts are given to the text based on the user requirement and can be modified at any time. Some of the commonly used fonts include Verdana, Times new roman etc. In this article, we will see different aspects such as syntax, constructors, methods and examples of JavaFX font in the following sections.
Syntax of JavaFX Font
Below is the syntax of JavaFX font.
Font f = Font.font(FONT, FONT TYPE, SIZE);
- Here, FONT denotes different fonts like verdana, times new roman etc.
- FONT TYPE is bold, italics etc.
- SIZE denotes the font size.
Constructors
Following are the two constructors of JavaFX font.
-
Font(double size):
A font will be constructed with “system” as the default face.
-
Font(Stringname, double size):
A font will be constructed with mentioned size and face name.
Methods
Let us see different methods of JavaFX font.
-
equals(Objectobj):
This method denotes whether any of the other objects available is same as this.
-
font(double s):
An appropriate font will be searched based on the font name and size that is default.
-
font(Stringf):
An appropriate font will be searched based on the mentioned font name and size that is the default.
-
font(Stringf, double s):
An appropriate font will be searched based on the mentioned font name and size.
-
font(Stringf, FontPosture p, double s):
An appropriate font will be searched based on the mentioned family name, posture and size.
-
font(Stringf, FontWeight w, double s):
An appropriate font will be searched based on the mentioned family name, weight and size.
-
font(Stringf, FontWeight w, FontPosture p, double s):
An appropriate font will be searched based on the mentioned family name, weight, posture and size.
-
getDefault():
Default font will be retrieved that is from the “System” family, “Regular “style, and consistent size with the desktop environment of the user,to the limit that can be determined.
-
getFamilies():
All the families of font will be retrieved on the system of the user, including the SDK fonts as well as application fonts.
-
get family():
Family of font will be retrieved.
-
getFontNames():
All the names of font will be retrieved on the system of the user, including the SDK fonts as well as application fonts.
-
getFontNames(Stringfamily):
All the names of font will be retrieved on the system of the user that is of the mentioned family, including the SDK fonts as well as application fonts.
-
getName():
Name of font will be retrieved.
-
getSize():
Size of font will be retrieved.
-
getStyle():
The font mentioned string explaining the style inside the font family.
-
hashCode():
Hash code will be retrieved for the font object.
-
loadFont(InputStreami, double s):
A font resource will be loaded from the mentioned input stream.
-
loadFont(StringurlStr, double size):
A font resource will be loaded from the mentioned URL.
-
toString():
Font object will be converted to a string representation.
Examples of JavaFX Font
Following are the examples are given below:
Example #1
Java Program that demonstrates the working of font class
Code:
importjavafx.application.Application; importjavafx.scene.Scene; importjavafx.scene.control.*; importjavafx.scene.layout.*; importjavafx.stage.Stage; importjavafx.scene.paint.*; importjavafx.scene.text.*; importjavafx.geometry.*; importjavafx.scene.shape.*; //main class publicclassFontSampleextends Application { // application launches here publicvoidstart(Stage st) { //exception handling try { // stage title st.setTitle(" Sample Font "); // TextFlow creation TextFlowtf = newTextFlow(); // create text Text txt = newText("Sample \n"); // color setting of the text txt.setFill(Color.RED); // FONT CREATION Font f = Font.font("Verdana", FontWeight.BOLD, 33); // Text font setting txt.setFont(f); // text setting tf.getChildren().add(txt); //line space setting tf.setLineSpacing(21.0f); // VBox creation VBoxvb = newVBox(tf); // svbox alignment setting vb.setAlignment(Pos.CENTER); // scene creation Scene sc = newScene(vb, 400, 200); // scene setting st.setScene(sc); st.show(); } //catch exception catch (Exception ec) { System.out.println(ec.getMessage()); } } // Main Method publicstaticvoidmain(String args[]) { // application launches here launch(args); } }
Example #2
Java Program that demonstrates font class with a drop box.
Code:
importjavafx.application.Application; importjavafx.scene.Scene; importjavafx.scene.control.*; importjavafx.scene.layout.*; importjavafx.stage.Stage; importjavafx.scene.paint.*; importjavafx.scene.text.*; importjavafx.geometry.*; importjavafx.collections.*; importjavafx.event.ActionEvent; importjavafx.event.EventHandler; publicclassFontSampleextends Application { // application launches here publicvoidstart(Stage st) { try { // stage title st.setTitle(" Sample Font "); // TextFlow creation TextFlowtf = newTextFlow(); // create text Text txt = newText("Sample \n"); // color setting of the text txt.setFill(Color.RED); // FONT CREATION Font f = Font.font("Verdana", FontWeight.BOLD, 33); // names String w[] = { "RED", "BLACK", "PINK", "LIGHT GREEN", "YELLOW", "BLUE", "CYAN", "ORANGE", "VIOLET", }; ComboBoxcb = newComboBox(FXCollections.observableArrayList(w)); // Create action event EventHandler< ActionEvent>event = newEventHandler< ActionEvent>() { publicvoidhandle(ActionEvente) { // set font of the text txt.setFont(Font.font((String)cb.getValue(), FontWeight.valueOf((String)cb.getValue()), 20)); } }; // Create action event EventHandler< ActionEvent>event1 = newEventHandler< ActionEvent>() { publicvoidhandle(ActionEvente) { // set font of the text txt.setFont(Font.font((String)cb.getValue(), FontWeight.valueOf((String)cb.getValue()), 20)); } }; // Set on action cb.setOnAction(event); // set font of the text txt.setFont(f); // set text tf.getChildren().add(txt); // set line spacing tf.setLineSpacing(20.0f); // create a HBox HBoxhbox = newHBox(cb); // create VBox VBoxvbox = newVBox(hbox, tf); // set spacing vbox.setSpacing(30.0); // set alignment of vbox vbox.setAlignment(Pos.CENTER); // create a scene Scenesc = newScene(vbox, 400, 300); // set the scene st.setScene(sc); st.show(); } catch (Exception ev) { System.out.println(ev.getMessage()); } } // Main Method publicstaticvoidmain(String args[]) { // launch the application launch(args); } }
Apply now for Advanced Java Training Course