To use a custom JavaFX-component in the FXML-description of the scene graph, it requires adaptation.
 
When declaring a class of the JavaFX-component in the FXML-description should be a way to automatically create an instance of the class. Therefore, the class of the JavaFX-component must either have a default constructor with no arguments or have a static factory method without arguments to create an instance of the class or have a class that implements the interface javafx.util.Builder and a class that implements the interface javafx.util.BuilderFactory.
To pass a parameter from the FXML-descriptions to an instance of the JavaFX-component class there should be a pair of get/set methods for the parameter.
 
For example, consider the use of a custom component of the cubic form with a hyperlink.
 
The main application class loads the FXML-description of the scene graph:
 
import javafx.application.Application;
 
import javafx.fxml.FXMLLoader;
 
import javafx.scene.Parent;
 
import javafx.scene.Scene;
 
import javafx.scene.paint.Color;
 
import javafx.stage.Stage;
 
 
 
public class JavaFXOGWebFXML extends Application {
 
   
 
    @Override
 
    public void start(Stage stage) throws Exception {
 
Parent root = FXMLLoader.load(getClass().getResource("OGWeb.fxml"));
 
       
 
        Scene scene = new Scene(root);
 
        scene.setFill(Color.BLACK);
 
        stage.setScene(scene);
 
        stage.show();
 
    }
 
 
 
    public static void main(String[] args) {
 
        launch(args);
 
    }
 
}
 
The FXML-description of the scene graph:
 
<?xml version="1.0" encoding="UTF-8"?>
 
 
 
<?import java.lang.*?>
 
<?import java.util.*?>
 
<?import javafx.scene.*?>
 
<?import javafx.scene.control.*?>
 
<?import javafx.scene.layout.*?>
 
<?import javafxogwebfxml.*?>
 
 
 
<AnchorPane id="AnchorPane" prefHeight="600" prefWidth="800" xmlns:fx="http://javafx.com/fxml" >
 
    <children>
 
        <MenuContainer layoutX="50" layoutY="50" label="Home" />
 
        <MenuContainer layoutX="160" layoutY="50" label="Services" />
 
         <MenuContainer layoutX="270" layoutY="50" label="Blog" />
 
         <MenuContainer layoutX="380" layoutY="50" label="Contacts" />       
 
    </children>
 
</AnchorPane>
 
This declares the custom component MenuContainer, to the instance of which a parameter label is passed. In this case, the class MenuContainer has the default constructor with no arguments:
 
import javafx.animation.Animation;
 
import javafx.animation.KeyFrame;
 
import javafx.animation.KeyValue;
 
import javafx.animation.Timeline;
 
import javafx.event.EventHandler;
 
import javafx.scene.Group;
 
import javafx.scene.control.Hyperlink;
 
import javafx.scene.control.HyperlinkBuilder;
 
import javafx.scene.input.MouseEvent;
 
import javafx.scene.layout.StackPane;
 
import javafx.scene.paint.Color;
 
import javafx.scene.shape.Rectangle;
 
import javafx.scene.shape.RectangleBuilder;
 
import javafx.scene.text.Font;
 
import javafx.scene.transform.Rotate;
 
import javafx.util.Duration;
 
 
 
public class MenuContainer extends Group {
 
final Rotate rx = new Rotate(0,Rotate.X_AXIS);
 
final Rotate ry = new Rotate(0,Rotate.Y_AXIS);
 
final Rotate rz = new Rotate(0,Rotate.Z_AXIS);
 
private double size=50.0;
 
private Color colorContainer=Color.BLUE;
 
private double shade=2.0;
 
private Hyperlink link;
 
private Color colorLabel=Color.WHITE;
 
private Font font=Font.font("Georgia", 18);
 
       
 
        public MenuContainer() {
 
            super();
 
            rx.setAngle(15);
 
            ry.setAngle(15);
 
            rz.setAngle(0);
 
            this.getTransforms().addAll(rz, ry, rx);
 
          final Group group=this;
 
//
 
final Rectangle   backFace =   RectangleBuilder.create() // back face
 
      .width(size*2).height(size)
 
      .fill(colorContainer.deriveColor(0.0, 1.0, (1 - 0.3*shade), 1.0))
 
      .translateX(-0.5*size)
 
      .translateY(-0.5*size)
 
      .translateZ(0.5*size)                    
 
      .build();           
 
//
 
final Rectangle   bottomFace =  RectangleBuilder.create() // bottom face
 
      .width(size*2).height(size)
 
      .fill(colorContainer.deriveColor(0.0, 1.0, (1 - 0.3*shade), 1.0))
 
      .translateX(-0.5*size)
 
      .translateY(0)
 
      .rotationAxis(Rotate.X_AXIS)
 
      .rotate(90)                 
 
      .build();         
 
 //
 
 final Rectangle   rightFace =   RectangleBuilder.create() // right face
 
      .width(size).height(size)
 
      .fill(colorContainer.deriveColor(0.0, 1.0, (1 - 0.3*shade), 1.0))
 
      .translateX(1*size)
 
      .translateY(-0.5*size)
 
      .rotationAxis(Rotate.Y_AXIS)
 
      .rotate(90)                  
 
      .build();       
 
 //
 
 final Rectangle   leftFace =   RectangleBuilder.create() // left face
 
      .width(size).height(size)
 
      .fill(colorContainer.deriveColor(0.0, 1.0, (1 - 0.3*shade), 1.0))
 
      .translateX(-1*size)
 
      .translateY(-0.5*size)
 
      .rotationAxis(Rotate.Y_AXIS)
 
      .rotate(90)                  
 
      .build();        
 
 //
 
 final Rectangle   topFace =  RectangleBuilder.create() // top face
 
      .width(size*2).height(size)
 
      .fill(colorContainer.deriveColor(0.0, 1.0, (1 - 0.2*shade), 1.0))
 
      .translateX(-0.5*size)
 
      .translateY(-1*size)
 
      .rotationAxis(Rotate.X_AXIS)
 
      .rotate(90)                   
 
      .build();      
 
 //          
 
 link = HyperlinkBuilder.create()                  
 
       .textFill(colorLabel)
 
       .font(font)
 
       .build();
 
 final StackPane face = new StackPane();
 
 face.getChildren().addAll(RectangleBuilder.create() // face
 
       .width(size*2).height(size)
 
       .fill(colorContainer)                 
 
       .build(),
 
       link
 
);
 
face.setTranslateX(-0.5*size);
 
face.setTranslateY(-0.5*size);
 
face.setTranslateZ(-0.5*size);
 
            
 
link.setOnMouseClicked(new EventHandler<MouseEvent>() {
 
            @Override
 
public void handle(MouseEvent event) {  
 
                   
 
} });
 
            
 
final   Timeline animation = new Timeline();
 
animation.getKeyFrames().addAll(
 
new KeyFrame(Duration.ZERO, new KeyValue(rx.angleProperty(), 15d)),                      
 
new KeyFrame(new Duration(1000), new KeyValue(rx.angleProperty(), 375d))                      
 
);
 
animation.setCycleCount(Animation.INDEFINITE);
 
      
 
group.setOnMouseDragged(new EventHandler<MouseEvent>() {
 
                @Override
 
public void handle(MouseEvent event) {         
 
animation.play();   
 
double x= event.getSceneX();
 
double y = event.getSceneY();        
 
group.setLayoutX(x);
 
group.setLayoutY(y);
 
group.setOnMouseReleased(new EventHandler<MouseEvent>() {
 
             @Override
 
public void handle(MouseEvent event) {
 
animation.stop();
 
rx.angleProperty().set(15);
 
}
 
});
 
} });         
 
//
 
            getChildren().addAll(backFace,bottomFace,rightFace,leftFace,topFace,face);           
 
}
 
       
 
public String getLabel(){
 
    return link.textProperty().get();   
 
}
 
public void setLabel(String value){
 
    link.textProperty().setValue(value);
 
}
 
}
 
 

Our services

Our developments are at the forefront of high technologies

We design and develop web sites

Individual site design
Creating dynamic sites
Website layout and programming

We develop information systems

Automation of business processes for small and medium business
Collection, storage and processing of data
Using cloud technologies

We create mobile apps

Integration with a Web site
Creating mobile versions of web sites
Using Augmented Reality and Computer Vision

About us

NOV Tech Solutions specializes in developing services for operational management of business, creating web and mobile applications on order

NOV Tech Solutions is a team of highly qualified professionals working for the result

We work quickly and efficiently, using the most modern technologies

We appreciate and take care of our customers, constantly improving the service and expanding the list of services

Our partners

Contacts