
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
JavaFXAnchorPane
The JavaFX Anchor Pane is used for anchoring to an offset from an anchor pane edges by its child node edges. If the anchor pane has a border or padding set, the off sets is measuring from the inside corner edges of the insets. Anchor pane lay out managing child of the child’s makes visible-property value and non-managing child are not considered for calculating layouts. We have facility to add CSS styles with Anchor pane of JavaFX. Anchor Pane is a JavaFX class, which is available in scene.layout.AnchorPane package. We can apply JavaFX Anchor pane with label, cylinder structure, rectangle structure, buttons etc.
Constructors
-
AnchorPane():
Creates an anchor pane object with new keyword without any argument in the constructor.
-
AnchorPane(Node n1, Node n2, Node n3,….):
Creates an anchor pane object with new keyword with required number of arguments in the constructor.
Frequently Used Methods
Below are the used methods:
-
setBottomAnchor(Node b, Double value):
setBottomAnchor() method is used to set Bottom anchor.
-
getBottomAnchor(Node b):
getBottomAnchor() method returns bottom anchor.
-
setLeftAnchor(Node l, Double value):
setLeftAnchor() method is used to set left anchor.
-
getLeftAnchor(Node l):
getLeftAnchor() method returns left anchor.
-
setRightAnchor(Node r, Double value):
setRightAnchor() method is used to set right anchor.
-
getRightAnchor(Node r):
getRightAnchor() method returns right anchor.
-
setTopAnchor(Node t, Double value):
setRightAnchor() method is used to set top anchor.
-
getTopAnchor(Node t):
getTopAnchor() method returns top anchor.
How does AnchorPane work in JavaFX?
Accessing JavaFX features user defined class must extends Application class.
- In JavaFX creating AnchorPane is first step. AnchorPane can instantiate by using new keyword.
- Creating Label or Button or any JavaFX element is second step.
- Create VBox or any other display(like TilePane or HBox as per requirement) class to add the items is third step.
- Fourth for apply show method on to it.
- Adding Scene reference screen to the Stage object reference is fifth step. Adding output screen to Stage. We will get this stage object reference from start predefined JavaFX method.
- Sixth step is showing output to the end user by applying show() method on the scene object.
Syntax:
AnchorPaneanchorPaneRef=new AnchorPane();
Syntax:
Label lableRef=new Label(“Any Message”);
anchorPaneRef.setTopAnchor(labelRef, value, value);
Syntax:
VBoxvBox=new VBox(anchorPaneRef); //Gives vertical box
Syntax:
Step is creating scene.
Scene screen = new Scene(vBox, length, width);
Syntax:
stage.setScene(screen);
Syntax:
stage.show();
Examples of JavaFXAnchorPane
Given below are the examples:
Example #1
Anchor pane with Label.
Code:
package com.anchorpanae; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; //importing AnchorPane class import javafx.scene.layout.AnchorPane; import javafx.stage.Stage; public class AnchorPaneLabel extends Application { // launch method invoked this start method public void start(Stage outStage) { try { // setting the tile for application outStage.setTitle("AnchorPane Label"); // create the label for adding the text to the application Label lableAnchor = new Label("I am anchor pane lable to show the demo."); // creating a AnchorPane object AnchorPaneanchorPaneObject = new AnchorPane(lableAnchor); //set the label to top anchor AnchorPane.setTopAnchor(lableAnchor, 20.0); //set the label to left anchor AnchorPane.setLeftAnchor(lableAnchor, 100.0); //set the label to right anchor AnchorPane.setRightAnchor(lableAnchor, 20.0); //set the label to bottom anchor AnchorPane.setBottomAnchor(lableAnchor, 20.0); // creating the scene to display output Scene screen = new Scene(anchorPaneObject, 410, 310); outStage.setScene(screen); // display the output outStage.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } // Main Method public static void main(String args[]) { // invoking main method from JVM launch(args); } }
Example #2
Anchor pane with Buttons.
Code:
package com.anchorpanae; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ScrollPane; //importing AnchorPane class import javafx.scene.layout.AnchorPane; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class AnchorPaneButton extends Application { // launch method invoked this start method public void start(Stage outStage) { try { // setting the tile for application outStage.setTitle("AnchorPane Buttons"); // creating the buttons for adding the text to the application Button button1 = new Button("First Button"); Button button2 = new Button("Second Button"); // creating a AnchorPane object AnchorPane anchorPaneObject1 = new AnchorPane(button1); //set the label to top anchor anchorPaneObject1.setTopAnchor(button1, 125.0); //set the label to left anchor anchorPaneObject1.setLeftAnchor(button1, 200.0); //set the label to right anchor anchorPaneObject1.setRightAnchor(button1, 100.0); //set the label to bottom anchor anchorPaneObject1.setBottomAnchor(button1, 500.0); //anchorPaneObject.getChildren().add(button1); anchorPaneObject1.setMinHeight(500); anchorPaneObject1.setMinWidth(500); // creating a AnchorPane object AnchorPane anchorPaneObject2 = new AnchorPane(button2); //set the label to top anchor anchorPaneObject2.setTopAnchor(button2, 150.0); //set the label to left anchor anchorPaneObject2.setLeftAnchor(button2, 200.0); //set the label to right anchor anchorPaneObject2.setRightAnchor(button2, 100.0); //set the label to bottom anchor anchorPaneObject2.setBottomAnchor(button2, 500.0); //anchorPaneObject.getChildren().add(button1); anchorPaneObject2.setMinHeight(500); anchorPaneObject2.setMinWidth(500) //creating VBox for adding anchor panes VBoxvBox=new VBox(); vBox.getChildren().add(anchorPaneObject1); vBox.getChildren().add(anchorPaneObject2); //scrollpane for scrolling ScrollPanescrollPnae=new ScrollPane(); scrollPnae.setContent(vBox); // creating the scene to display output Scene screen = new Scene(scrollPnae, 400, 300); outStage.setScene(screen); // display the output outStage.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } // Main Method public static void main(String args[]) { // invoking main method from JVM launch(args); } }
Example #3
Anchor pane with Rectangle shape.
Code:
package com.anchorpanae; import javafx.application.Application; import javafx.scene.Scene; //importing AnchorPane class import javafx.scene.layout.AnchorPane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class AnchorPaneImage extends Application { // launch method invoked this start method public void start(Stage outStage) { try { // setting the tile for application outStage.setTitle("AnchorPane Rectangle Shape"); //creating rectangle shape Rectangle rectangleShape = new Rectangle(300,200,Color.GREEN); rectangleShape.relocate(70,70); // creating a AnchorPane object AnchorPaneanchorPaneObject = new AnchorPane(rectangleShape); //set the label to top anchor AnchorPane.setTopAnchor(rectangleShape, 20.0); //set the label to left anchor AnchorPane.setLeftAnchor(rectangleShape, 100.0); //set the label to right anchor AnchorPane.setRightAnchor(rectangleShape, 20.0); //set the label to bottom anchor AnchorPane.setBottomAnchor(rectangleShape, 20.0); // creating the scene to display output Scene screen = new Scene(anchorPaneObject, 500, 400); outStage.setScene(screen); // display the output outStage.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } // Main Method public static void main(String args[]) { // invoking main method from JVM launch(args); } }
Apply now for Advanced Java Training Course