title: JavaFX Complex Neuomorphism Design Causing Lagging of Application
body: <p>I'm Creating a loading screen for my application which has complex Neumorphism Design using InnerShadow, although CPU and RAM usage is less, the application causes lagging effect for animation like Circular Progress Indicator of Gluon charm-glisten.jar as well as PathTransition animation. In this loading screen you can see a red rectangle moving around the design and the progress indicator in blue color in the innermost layer</p>
  <p>Java Code:</p>
  <pre><code>package application;
      
  import java.net.URL;
  import java.util.*;
  
  import com.gluonhq.charm.glisten.control.ProgressIndicator;
  
  import javafx.animation.*;
  import javafx.animation.PathTransition.*;
  import javafx.application.*;
  import javafx.concurrent.*;
  import javafx.event.*;
  import javafx.fxml.*;
  import javafx.stage.*;
  import javafx.util.*;
  import javafx.scene.*;
  import javafx.scene.input.*;
  import javafx.scene.layout.*;
  import javafx.scene.paint.*;
  import javafx.scene.shape.*;
  
  public class Main extends Application implements Initializable
  {
      private double xOffset = 0;
      private double yOffset = 0;
      
      @FXML
      ProgressIndicator pg1;
      static AnchorPane root;
      private PathTransition pathTransitionCircle;
      public void start(Stage primaryStage) 
      {
          try 
          {
              primaryStage.initStyle(StageStyle.TRANSPARENT);
              root = FXMLLoader.load(getClass().getResource(&quot;Test1.fxml&quot;));
              Scene scene = new Scene(root,600,400);
              scene.getStylesheets().add(getClass().getResource(&quot;application.css&quot;).toExternalForm());
              scene.setFill(javafx.scene.paint.Color.TRANSPARENT);
              primaryStage.setScene(scene);
              
              primaryStage.show();
              
              root.setOnMousePressed(new EventHandler&lt;MouseEvent&gt;() 
              {
                  public void handle(MouseEvent e)
                  {
                      xOffset = e.getSceneX();
                      yOffset = e.getSceneY();
                      
                  }
              });
              
              root.setOnMouseDragged(new EventHandler&lt;MouseEvent&gt;() 
              {
                  public void handle(MouseEvent e) 
                  {
                      primaryStage.setX(e.getScreenX() - xOffset);
                      primaryStage.setY(e.getScreenY() - yOffset);
                  }
              });
              
               Rectangle rect2 = new Rectangle(0, 0, 20, 20);
               rect2.setArcHeight(10);
               rect2.setArcWidth(10);
               rect2.setFill(Color.RED);
               root.getChildren().add(rect2);
                  
               Path path2 = createEllipsePath(400, 200, 150, 150, 0);
               path2.setLayoutX(57);
               path2.setLayoutY(10);
               root.getChildren().add(path2);
  
               pathTransitionCircle = new PathTransition();
               pathTransitionCircle.setDuration(Duration.seconds(6));
               pathTransitionCircle.setPath(path2);
               pathTransitionCircle.setNode(rect2);
               pathTransitionCircle.setOrientation(OrientationType.ORTHOGONAL_TO_TANGENT);
               pathTransitionCircle.setCycleCount(PathTransition.INDEFINITE);
               pathTransitionCircle.setInterpolator(Interpolator.LINEAR);
               pathTransitionCircle.setAutoReverse(false);
               pathTransitionCircle.play();
          }
          catch(Exception e) 
          {
              e.printStackTrace();
          }
      }
      
      public static void main(String[] args) 
      {
          launch(args);
      }
  
      @Override
      public void initialize(URL arg0, ResourceBundle arg1) 
      {
          Task&lt;Void&gt; task = new Task&lt;Void&gt;()
          {
              protected Void call() throws Exception 
              {
                  for (int i = 0; i &lt;= 100; i++) 
                  {
                      updateProgress(i, 100);
                      Thread.sleep(40);
                  }
                  //Platform.runLater(() -&gt; primaryStage.close());
                  return null;
              }
          };
          pg1.progressProperty().unbind();
          pg1.progressProperty().bind(task.progressProperty());
          
          Thread th = new Thread(task);
          th.setDaemon(true);
          th.start();
          task.setOnSucceeded(new EventHandler&lt;WorkerStateEvent&gt;() 
          {
              public void handle(WorkerStateEvent arg0) 
              {
                  try 
                  {
                          /*primaryStage.close();
                          primaryStage = null;
                          System.gc();
                          FXML_Loader f1 = new FXML_Loader();
                          f1.intermediate();*/
                  }
                  catch (Exception e)
                  {
                      e.printStackTrace();
                  }
              }
              
          });
      }
      private Path createEllipsePath(double centerX, double centerY, double radiusX, double radiusY, double rotate)
      {
          ArcTo arcTo = new ArcTo();
          arcTo.setX(centerX - radiusX + 1); // to simulate a full 360 degree celcius circle.
          arcTo.setY(centerY - radiusY);
          arcTo.setSweepFlag(false);
          arcTo.setLargeArcFlag(true);
          arcTo.setRadiusX(radiusX);
          arcTo.setRadiusY(radiusY);
          arcTo.setXAxisRotation(rotate);
  
          Path path = new Path();
          path.getElements().addAll(
                  new MoveTo(centerX - radiusX, centerY - radiusY),
                  arcTo,
                  new ClosePath()); // close 1 px gap.
          path.setStroke(Color.BLUE);
          path.getStrokeDashArray().setAll(5d, 5d);
          return path;
      }
  }
  
  </code></pre>
  <p>FXML Code:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  
  &lt;?import com.gluonhq.charm.glisten.control.ProgressIndicator?&gt;
  &lt;?import javafx.geometry.Insets?&gt;
  &lt;?import javafx.scene.control.Label?&gt;
  &lt;?import javafx.scene.effect.InnerShadow?&gt;
  &lt;?import javafx.scene.image.Image?&gt;
  &lt;?import javafx.scene.image.ImageView?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  &lt;?import javafx.scene.layout.VBox?&gt;
  &lt;?import javafx.scene.text.Font?&gt;
  
  &lt;AnchorPane maxHeight=&quot;-Infinity&quot; maxWidth=&quot;-Infinity&quot; minHeight=&quot;-Infinity&quot; minWidth=&quot;-Infinity&quot; prefHeight=&quot;400.0&quot; prefWidth=&quot;600.0&quot; style=&quot;-fx-background-color: transparent;&quot; xmlns=&quot;http://javafx.com/javafx/11.0.1&quot; xmlns:fx=&quot;http://javafx.com/fxml/1&quot; fx:controller=&quot;application.Main&quot;&gt;
     &lt;children&gt;
        &lt;VBox alignment=&quot;CENTER&quot; layoutX=&quot;163.5&quot; layoutY=&quot;63.5&quot; prefHeight=&quot;290.0&quot; prefWidth=&quot;290.0&quot; style=&quot;-fx-background-color: #3D4956; -fx-background-radius: 150;&quot;&gt;
           &lt;effect&gt;
              &lt;InnerShadow color=&quot;#00000070&quot; offsetX=&quot;-4.0&quot; offsetY=&quot;-4.0&quot;&gt;
                 &lt;input&gt;
                    &lt;InnerShadow color=&quot;#a7a7a7bf&quot; offsetX=&quot;4.0&quot; offsetY=&quot;4.0&quot; /&gt;
                 &lt;/input&gt;
              &lt;/InnerShadow&gt;
           &lt;/effect&gt;
           &lt;children&gt;
              &lt;VBox alignment=&quot;CENTER&quot; prefHeight=&quot;200.0&quot; prefWidth=&quot;100.0&quot; style=&quot;-fx-background-color: #3D4956; -fx-background-radius: 150;&quot; VBox.vgrow=&quot;ALWAYS&quot;&gt;
                 &lt;VBox.margin&gt;
                    &lt;Insets bottom=&quot;15.0&quot; left=&quot;15.0&quot; right=&quot;15.0&quot; top=&quot;15.0&quot; /&gt;
                 &lt;/VBox.margin&gt;
                 &lt;effect&gt;
                    &lt;InnerShadow color=&quot;#0000008c&quot; offsetX=&quot;4.0&quot; offsetY=&quot;4.0&quot;&gt;
                       &lt;input&gt;
                          &lt;InnerShadow color=&quot;#a6a6a65c&quot; offsetX=&quot;-4.0&quot; offsetY=&quot;-4.0&quot; /&gt;
                       &lt;/input&gt;
                    &lt;/InnerShadow&gt;
                 &lt;/effect&gt;
                 &lt;children&gt;
                    &lt;VBox alignment=&quot;CENTER&quot; prefHeight=&quot;200.0&quot; prefWidth=&quot;100.0&quot; style=&quot;-fx-background-color: #3D4956; -fx-background-radius: 150;&quot; VBox.vgrow=&quot;ALWAYS&quot;&gt;
                       &lt;VBox.margin&gt;
                          &lt;Insets bottom=&quot;15.0&quot; left=&quot;15.0&quot; right=&quot;15.0&quot; top=&quot;15.0&quot; /&gt;
                       &lt;/VBox.margin&gt;
                       &lt;effect&gt;
                          &lt;InnerShadow color=&quot;#0000008c&quot; offsetX=&quot;-4.0&quot; offsetY=&quot;-4.0&quot;&gt;
                             &lt;input&gt;
                                &lt;InnerShadow color=&quot;#a6a6a65c&quot; offsetX=&quot;4.0&quot; offsetY=&quot;4.0&quot; /&gt;
                             &lt;/input&gt;
                          &lt;/InnerShadow&gt;
                       &lt;/effect&gt;
                       &lt;children&gt;
                          &lt;VBox prefHeight=&quot;200.0&quot; prefWidth=&quot;100.0&quot; style=&quot;-fx-background-color: #3D4956; -fx-background-radius: 150;&quot; VBox.vgrow=&quot;ALWAYS&quot;&gt;
                             &lt;VBox.margin&gt;
                                &lt;Insets bottom=&quot;15.0&quot; left=&quot;15.0&quot; right=&quot;15.0&quot; top=&quot;15.0&quot; /&gt;
                             &lt;/VBox.margin&gt;
                             &lt;effect&gt;
                                &lt;InnerShadow color=&quot;#0000008c&quot; offsetX=&quot;4.0&quot; offsetY=&quot;4.0&quot;&gt;
                                   &lt;input&gt;
                                      &lt;InnerShadow color=&quot;#a6a6a65c&quot; /&gt;
                                   &lt;/input&gt;
                                &lt;/InnerShadow&gt;
                             &lt;/effect&gt;
                             &lt;children&gt;
                                &lt;VBox alignment=&quot;CENTER&quot; prefHeight=&quot;200.0&quot; prefWidth=&quot;100.0&quot; style=&quot;-fx-background-color: #3D4956; -fx-background-radius: 150;&quot; VBox.vgrow=&quot;ALWAYS&quot;&gt;
                                   &lt;VBox.margin&gt;
                                      &lt;Insets bottom=&quot;15.0&quot; left=&quot;15.0&quot; right=&quot;15.0&quot; top=&quot;15.0&quot; /&gt;
                                   &lt;/VBox.margin&gt;
                                   &lt;effect&gt;
                                      &lt;InnerShadow color=&quot;#0000008c&quot; offsetX=&quot;-4.0&quot; offsetY=&quot;-4.0&quot;&gt;
                                         &lt;input&gt;
                                            &lt;InnerShadow color=&quot;#a6a6a65c&quot; offsetX=&quot;4.0&quot; offsetY=&quot;4.0&quot; /&gt;
                                         &lt;/input&gt;
                                      &lt;/InnerShadow&gt;
                                   &lt;/effect&gt;
                                   &lt;children&gt;
                                      &lt;AnchorPane prefHeight=&quot;58.0&quot; prefWidth=&quot;141.0&quot; style=&quot;-fx-background-color: #3D4956; -fx-background-radius: 150;&quot; VBox.vgrow=&quot;ALWAYS&quot;&gt;
                                         &lt;VBox.margin&gt;
                                            &lt;Insets bottom=&quot;15.0&quot; left=&quot;15.0&quot; right=&quot;15.0&quot; top=&quot;15.0&quot; /&gt;
                                         &lt;/VBox.margin&gt;
                                         &lt;effect&gt;
                                            &lt;InnerShadow color=&quot;#0000008c&quot; offsetX=&quot;4.0&quot; offsetY=&quot;4.0&quot;&gt;
                                               &lt;input&gt;
                                                  &lt;InnerShadow color=&quot;#a6a6a65c&quot; offsetX=&quot;-4.0&quot; offsetY=&quot;-4.0&quot; /&gt;
                                               &lt;/input&gt;
                                            &lt;/InnerShadow&gt;
                                         &lt;/effect&gt;
                                         &lt;children&gt;
                                            &lt;ImageView fitHeight=&quot;42.0&quot; fitWidth=&quot;50.0&quot; layoutX=&quot;49.0&quot; layoutY=&quot;40.0&quot; pickOnBounds=&quot;true&quot; preserveRatio=&quot;true&quot;&gt;
                                               &lt;image&gt;
                                                  &lt;Image url=&quot;@logo/database1.png&quot; /&gt;
                                               &lt;/image&gt;
                                            &lt;/ImageView&gt;
                                            &lt;Label layoutX=&quot;57.0&quot; layoutY=&quot;81.0&quot; prefHeight=&quot;19.0&quot; prefWidth=&quot;34.0&quot; text=&quot;SQL&quot; textFill=&quot;YELLOW&quot;&gt;
                                               &lt;font&gt;
                                                  &lt;Font name=&quot;System Bold Italic&quot; size=&quot;14.0&quot; /&gt;
                                               &lt;/font&gt;
                                            &lt;/Label&gt;
                                            &lt;Label layoutX=&quot;38.0&quot; layoutY=&quot;97.0&quot; prefHeight=&quot;20.0&quot; prefWidth=&quot;73.0&quot; text=&quot;Developer&quot; textFill=&quot;YELLOW&quot;&gt;
                                               &lt;font&gt;
                                                  &lt;Font name=&quot;System Bold Italic&quot; size=&quot;14.0&quot; /&gt;
                                               &lt;/font&gt;
                                            &lt;/Label&gt;
                                            &lt;ProgressIndicator fx:id=&quot;pg1&quot; layoutX=&quot;8.0&quot; layoutY=&quot;7.0&quot; prefHeight=&quot;108.0&quot; prefWidth=&quot;122.0&quot; progress=&quot;1.0&quot; radius=&quot;60.0&quot; /&gt;
                                         &lt;/children&gt;
                                      &lt;/AnchorPane&gt;
                                   &lt;/children&gt;
                                &lt;/VBox&gt;
                             &lt;/children&gt;
                          &lt;/VBox&gt;
                       &lt;/children&gt;
                    &lt;/VBox&gt;
                 &lt;/children&gt;
              &lt;/VBox&gt;
           &lt;/children&gt;
        &lt;/VBox&gt;
     &lt;/children&gt;
  &lt;/AnchorPane&gt;
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/UKuFQ.png" rel="nofollow noreferrer">Loading Screen Design</a></p>