Как анимировать лейбл в pane c учетом размера окна программы?

134
06 июня 2019, 17:40

В программе имеются коричневые квадраты слева(кнопки активации настроек) при нажатии на квадрат, из него выкатывается прямоугольник такого же цвета(HBox), внутри которого stackPane и внутри StackPane иконки, а лейбл(упакован в Hbox) справа укатывается вправо. Анимацию отката лейбла я делал путем уменьшения PrefWidth лейбла.

Программа работает нормально в полноэкранном режиме, вся анимация происходит так как и было задуманно, НО! при ресайзе окна программы, анимация всех блоков работает не так, она получается как бы работает, но её не видно, потому что размер всех блоков стал другим от ресайза, а в анимации прописаны конкретные размеры уменьшения prefWidth

Вот пример как у меня раелизована анимация одного label:

if (btnPref1.isSelected()) {
Timeline tl1 = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category1.prefWidthProperty(), 1610)));
tl1.play();
}
else {Timeline tlOne = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category1.prefWidthProperty(), 1900)));
      tlOne.play();
}

1.Как сделать,чтобы анимация была видна с учетом размера окна программы? 2.Возможно ли реализовать другую анимацию, которая бы откатывала лейбл вправо при клике на коричневый квадрат с учетом размера окна программы?

Видео процесса

класс Controller:

package card;
import javafx.animation.*;
import javafx.scene.control.*;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.layout.*;
import javafx.event.ActionEvent;
import javafx.util.Duration;
import java.net.URL;
import java.util.ResourceBundle;
public class Controller implements Initializable {

  @FXML  private HBox anchorRow;
  @FXML  private StackPane hBoxCat0;
  @FXML  private Button btnPalette;
  @FXML  private Button btnFont;
  @FXML  private Button btnQuestCards;
  @FXML  private Button btnNonQuestCards;
  @FXML  private ToggleButton btnPref1;
  @FXML  private ToggleButton btnPref2;
  @FXML  private ToggleButton btnPref3;
  @FXML  private ToggleButton btnPref4;
  @FXML  private ToggleButton btnPref5;
  @FXML  private ToggleButton btnPref6;
  @FXML  private ToggleButton btnPref7;
  @FXML  private ToggleButton btnPref8;
  @FXML  private Label category1;
  @FXML  private Label category2;
  @FXML  private Label category3;
  @FXML  private Label category4;
  @FXML  private Label category5;
  @FXML  private Label category6;
  @FXML  private Label category7;
  @FXML  private Label category8;
  @FXML  private ToggleGroup group;

  @FXML
  public void initialize(URL location, ResourceBundle resources) {
  }
  //create animation timeline to show preference block
  public void showPrefAnimation() {
    Timeline tmHbox = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(hBoxCat0.prefWidthProperty(), 250)));
    tmHbox.play();
    TranslateTransition ttPalette = new TranslateTransition(Duration.millis(300), btnPalette);
    TranslateTransition ttFont = new TranslateTransition(Duration.millis(300), btnFont);
    TranslateTransition ttQuest = new TranslateTransition(Duration.millis(300), btnQuestCards);
    TranslateTransition ttNonQuest = new TranslateTransition(Duration.millis(300), btnNonQuestCards);
    ttPalette.setFromX(0);
    ttFont.setFromX(0);
    ttQuest.setFromX(0);
    ttNonQuest.setFromX(0);
    ttPalette.setToX(40);
    ttFont.setToX(93);
    ttQuest.setToX(143);
    ttNonQuest.setToX(195);
    ttPalette.play();
    ttFont.play();
    ttQuest.play();
    ttNonQuest.play();
  }
  //create animation timeline to hide preference block
  public void hidePrefAnimation() {
    Timeline tmHboxCat = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(hBoxCat0.prefWidthProperty(), 10)));
    tmHboxCat.play();
    TranslateTransition ttPalette = new TranslateTransition(Duration.millis(300), btnPalette);
    TranslateTransition ttFont = new TranslateTransition(Duration.millis(300), btnFont);
    TranslateTransition ttQuest = new TranslateTransition(Duration.millis(300), btnQuestCards);
    TranslateTransition ttNonQuest = new TranslateTransition(Duration.millis(300), btnNonQuestCards);
    ttPalette.setFromX(40);
    ttFont.setFromX(93);
    ttQuest.setFromX(143);
    ttNonQuest.setFromX(195);
    ttPalette.setToX(0);
    ttFont.setToX(0);
    ttQuest.setToX(0);
    ttNonQuest.setToX(0);
    ttPalette.play();
    ttFont.play();
    ttQuest.play();
    ttNonQuest.play();
  }

  //Open preference window and make width animation for category 1
  @FXML
  void openPreference1(ActionEvent event) {
    if (btnPref1.isSelected()) {
      GridPane.setRowIndex(anchorRow, 0);
      Timeline tl1 = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category1.prefWidthProperty(), 1610)));
      showPrefAnimation();
      tl1.play();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> button.setDisable(true));
      btnPref1.setDisable(false);
    }
    else  {
      Timeline tlOne = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category1.prefWidthProperty(), 1900)));
      tlOne.play();
      hidePrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> {
      button.setDisable(false);
      });
    }
  }
  //Open preference window and make width animation for category 2
  @FXML
  void openPreference2(ActionEvent event) {
    if (btnPref2.isSelected()) {
      GridPane.setRowIndex(anchorRow, 1);
      Timeline tl2 = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category2.prefWidthProperty(), 1610)));
      tl2.play();
      showPrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> button.setDisable(true));
      btnPref2.setDisable(false);
    }
  else  {
     Timeline tlTwo = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category2.prefWidthProperty(), 1900)));
      tlTwo.play();
      hidePrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> {
      button.setDisable(false);
      });
  }
  }
  //Open preference window and make width animation for category 3
  @FXML
  void openPreference3(ActionEvent event) {
      if (btnPref3.isSelected()) {
      GridPane.setRowIndex(anchorRow, 2);
      Timeline tl3 = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category3.prefWidthProperty(), 1610)));
        tl3.play();
      showPrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> button.setDisable(true));
      btnPref3.setDisable(false);
    }
    else  {
      Timeline tlThree = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category3.prefWidthProperty(), 1900)));
        tlThree.play();
      hidePrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> {
      button.setDisable(false);
      });
    }
  }
  //Open preference window and make width animation for category 4
  @FXML
  void openPreference4(ActionEvent event) {
    if (btnPref4.isSelected()) {
      GridPane.setRowIndex(anchorRow, 3);
      Timeline tl4 = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category4.prefWidthProperty(), 1610)));
      tl4.play();
      showPrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> button.setDisable(true));
      btnPref4.setDisable(false);
    }
    else  {
      Timeline tlFour = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category4.prefWidthProperty(), 1900)));
      tlFour.play();
      hidePrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> {
      button.setDisable(false);
      });
    }
  }
  //Open preference window and make width animation for category 5
  @FXML
  void openPreference5(ActionEvent event) {
    if (btnPref5.isSelected()) {
      GridPane.setRowIndex(anchorRow, 4);
      Timeline tl5 = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category5.prefWidthProperty(), 1610)));
      tl5.play();
      showPrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> button.setDisable(true));
      btnPref5.setDisable(false);
    }
    else  {
      Timeline tlFive = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category5.prefWidthProperty(), 1900)));
      tlFive.play();
      hidePrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> {
      button.setDisable(false);
      });
    }
  }
  //Open preference window and make width animation for category 6
  @FXML
  void openPreference6(ActionEvent event) {
    if (btnPref6.isSelected()) {
      GridPane.setRowIndex(anchorRow, 5);
      Timeline tl6 = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category6.prefWidthProperty(), 1610)));
      tl6.play();
      showPrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> button.setDisable(true));
      btnPref6.setDisable(false);
    }
    else  {
      Timeline tlSix = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category6.prefWidthProperty(), 1900)));
      tlSix.play();
      hidePrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> {
      button.setDisable(false);
      });
    }
  }
  //Open preference window and make width animation for category 7
  @FXML
  void openPreference7(ActionEvent event) {
    if (btnPref7.isSelected()) {
      GridPane.setRowIndex(anchorRow, 6);
      Timeline tl7 = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category7.prefWidthProperty(), 1610)));
      tl7.play();
      showPrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> button.setDisable(true));
      btnPref7.setDisable(false);
    }
    else  {
      Timeline tlSeven = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category7.prefWidthProperty(), 1900)));
      tlSeven.play();
      hidePrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> {
      button.setDisable(false);
      });
    }
  }
  //Open preference window and make width animation for category 8
  @FXML
  void openPreference8(ActionEvent event) {
    if (btnPref8.isSelected()) {
      GridPane.setRowIndex(anchorRow, 7);
      Timeline tl8 = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category8.prefWidthProperty(), 1610)));
      tl8.play();
      showPrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> button.setDisable(true));
      btnPref8.setDisable(false);
    }
    else  {
      Timeline tlEight = new Timeline(new KeyFrame(Duration.millis(300), new KeyValue(category8.prefWidthProperty(), 1900)));
      tlEight.play();
      hidePrefAnimation();
      group.getToggles().stream().map((toggle) -> (ToggleButton)toggle).forEach((button) -> {
      button.setDisable(false);
      });
    }
  }

}

FXML:

<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.String?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<AnchorPane fx:id="mainAnchor" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="900.0" prefWidth="1900.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="card.Controller">

   <children>
      <GridPane alignment="CENTER" layoutY="19.0" maxHeight="1.7976931348623157E308" maxWidth="-Infinity" styleClass="background" stylesheets="@style.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <columnConstraints>
          <ColumnConstraints maxWidth="1.7976931348623157E308" prefWidth="70.0" />
            <ColumnConstraints maxWidth="1.7976931348623157E308" prefWidth="70.0" />
            <ColumnConstraints maxWidth="1.7976931348623157E308" prefWidth="70.0" />
            <ColumnConstraints hgrow="NEVER" maxWidth="1.7976931348623157E308" prefWidth="70.0" />
          <ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" prefWidth="1419.0" />
        </columnConstraints>
        <rowConstraints>
          <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
            <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
            <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
            <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
            <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
          <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
          <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
            <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
        </rowConstraints>
         <children>
            <HBox fx:id="anchorRow" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnSpan="4" GridPane.hgrow="ALWAYS">
               <children>
                  <StackPane fx:id="hBoxCat0" alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="10.0" styleClass="anchor-pref" stylesheets="@style.css">
                     <children>
                        <Button fx:id="btnPalette" mnemonicParsing="false" prefHeight="73.0" prefWidth="45.0" stylesheets="@style.css">
                           <styleClass>
                              <String fx:value="btnPalette" />
                              <String fx:value="icon-image-pref" />
                           </styleClass>
                        </Button>
                        <Button fx:id="btnFont" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="73.0" prefWidth="45.0" stylesheets="@style.css">
                           <styleClass>
                              <String fx:value="btnFonts" />
                              <String fx:value="icon-image-pref" />
                           </styleClass>
                        </Button>
                        <Button fx:id="btnQuestCards" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="73.0" prefWidth="45.0" stylesheets="@style.css">
                           <styleClass>
                              <String fx:value="btnQuestCards" />
                              <String fx:value="icon-image-pref" />
                           </styleClass>
                        </Button>
                        <Button fx:id="btnNonQuestCards" contentDisplay="CENTER" mnemonicParsing="false" prefHeight="73.0" prefWidth="45.0" stylesheets="@style.css">
                           <styleClass>
                              <String fx:value="btnNonQuestCards" />
                              <String fx:value="icon-image-pref" />
                           </styleClass>
                        </Button>
                     </children>
                  </StackPane>
               </children>
               <GridPane.margin>
                  <Insets bottom="20.0" left="20.0" right="10.0" top="20.0" />
               </GridPane.margin>
            </HBox>
            <AnchorPane>
               <children>
                  <ToggleButton fx:id="btnPref1" graphicTextGap="1.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#openPreference1" prefHeight="100.0" prefWidth="70.0" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="20.0">
                     <toggleGroup>
                        <ToggleGroup fx:id="group" />
                     </toggleGroup></ToggleButton>
               </children>
            </AnchorPane>
            <AnchorPane layoutX="10.0" layoutY="10.0" GridPane.rowIndex="1">
               <children>
                  <ToggleButton fx:id="btnPref2" graphicTextGap="1.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#openPreference2" prefHeight="100.0" prefWidth="70.0" toggleGroup="$group" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="20.0" />
               </children>
            </AnchorPane>
            <AnchorPane layoutX="10.0" layoutY="123.0" GridPane.rowIndex="2">
               <children>
                  <ToggleButton fx:id="btnPref3" graphicTextGap="1.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#openPreference3" prefHeight="100.0" prefWidth="70.0" toggleGroup="$group" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="20.0" />
               </children>
            </AnchorPane>
            <AnchorPane layoutX="10.0" layoutY="236.0" GridPane.rowIndex="3">
               <children>
                  <ToggleButton fx:id="btnPref4" graphicTextGap="1.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#openPreference4" prefHeight="100.0" prefWidth="70.0" toggleGroup="$group" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="20.0" />
               </children>
            </AnchorPane>
            <AnchorPane layoutX="10.0" layoutY="349.0" GridPane.rowIndex="4">
               <children>
                  <ToggleButton fx:id="btnPref5" graphicTextGap="1.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#openPreference5" prefHeight="100.0" prefWidth="70.0" toggleGroup="$group" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="20.0" />
               </children>
            </AnchorPane>
            <AnchorPane layoutX="10.0" layoutY="10.0" GridPane.rowIndex="5">
               <children>
                  <ToggleButton fx:id="btnPref6" graphicTextGap="1.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#openPreference6" prefHeight="100.0" prefWidth="70.0" toggleGroup="$group" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="20.0" />
               </children>
            </AnchorPane>
            <AnchorPane layoutX="10.0" layoutY="574.0" GridPane.rowIndex="6">
               <children>
                  <ToggleButton fx:id="btnPref7" graphicTextGap="1.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#openPreference7" prefHeight="100.0" prefWidth="70.0" toggleGroup="$group" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="20.0" />
               </children>
            </AnchorPane>
            <AnchorPane layoutX="10.0" layoutY="686.0" GridPane.rowIndex="7">
               <children>
                  <ToggleButton fx:id="btnPref8" graphicTextGap="1.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#openPreference8" prefHeight="100.0" prefWidth="70.0" toggleGroup="$group" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="20.0" />
               </children>
            </AnchorPane>
            <HBox layoutX="90.0" layoutY="818.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="RIGHT_TO_LEFT" GridPane.columnIndex="1" GridPane.columnSpan="4" GridPane.hgrow="ALWAYS">
               <children>
                  <Label fx:id="category1" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" prefHeight="73.0" prefWidth="1900.0" snapToPixel="false" text="Category 1">
                     <HBox.margin>
                        <Insets />
                     </HBox.margin>
                  </Label>
               </children>
               <GridPane.margin>
                  <Insets bottom="20.0" left="10.0" right="20.0" top="20.0" />
               </GridPane.margin>
            </HBox>
            <HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="RIGHT_TO_LEFT" GridPane.columnIndex="1" GridPane.columnSpan="4" GridPane.rowIndex="1">
               <children>
                  <Label fx:id="category2" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" prefHeight="75.0" prefWidth="1900.0" snapToPixel="false" text="Category 2" />
               </children>
               <GridPane.margin>
                  <Insets bottom="20.0" left="10.0" right="20.0" top="20.0" />
               </GridPane.margin>
            </HBox>
            <HBox layoutX="90.0" layoutY="142.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="RIGHT_TO_LEFT" GridPane.columnIndex="1" GridPane.columnSpan="4" GridPane.rowIndex="2">
               <children>
                  <Label fx:id="category3" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" prefHeight="75.0" prefWidth="1900.0" snapToPixel="false" text="Category 3" />
               </children>
               <GridPane.margin>
                  <Insets bottom="20.0" left="10.0" right="20.0" top="20.0" />
               </GridPane.margin>
            </HBox>
            <HBox layoutX="90.0" layoutY="255.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="RIGHT_TO_LEFT" GridPane.columnIndex="1" GridPane.columnSpan="4" GridPane.rowIndex="3">
               <children>
                  <Label fx:id="category4" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" prefHeight="75.0" prefWidth="1900.0" snapToPixel="false" text="Category 4" />
               </children>
               <GridPane.margin>
                  <Insets bottom="20.0" left="10.0" right="20.0" top="20.0" />
               </GridPane.margin>
            </HBox>
            <HBox layoutX="90.0" layoutY="368.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="RIGHT_TO_LEFT" GridPane.columnIndex="1" GridPane.columnSpan="4" GridPane.rowIndex="4">
               <children>
                  <Label fx:id="category5" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" prefHeight="75.0" prefWidth="1900.0" snapToPixel="false" text="Category 5" />
               </children>
               <GridPane.margin>
                  <Insets bottom="20.0" left="10.0" right="20.0" top="20.0" />
               </GridPane.margin>
            </HBox>
            <HBox layoutX="90.0" layoutY="481.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="RIGHT_TO_LEFT" GridPane.columnIndex="1" GridPane.columnSpan="4" GridPane.rowIndex="5">
               <children>
                  <Label fx:id="category6" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" prefHeight="75.0" prefWidth="1900.0" snapToPixel="false" text="Category 6" />
               </children>
               <GridPane.margin>
                  <Insets bottom="20.0" left="10.0" right="20.0" top="20.0" />
               </GridPane.margin>
            </HBox>
            <HBox layoutX="90.0" layoutY="593.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="RIGHT_TO_LEFT" GridPane.columnIndex="1" GridPane.columnSpan="4" GridPane.rowIndex="6">
               <children>
                  <Label fx:id="category7" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" prefHeight="75.0" prefWidth="1900.0" snapToPixel="false" text="Category 7" />
               </children>
               <GridPane.margin>
                  <Insets bottom="20.0" left="10.0" right="20.0" top="20.0" />
               </GridPane.margin>
            </HBox>
            <HBox layoutX="90.0" layoutY="705.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="RIGHT_TO_LEFT" GridPane.columnIndex="1" GridPane.columnSpan="4" GridPane.rowIndex="7">
               <children>
                  <Label fx:id="category8" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" prefHeight="75.0" prefWidth="1900.0" snapToPixel="false" text="Category 8" />
               </children>
               <GridPane.margin>
                  <Insets bottom="20.0" left="10.0" right="20.0" top="20.0" />
               </GridPane.margin>
            </HBox>
         </children>
      </GridPane>
   </children>
</AnchorPane>
Answer 1

Проверьте размеры области, в котором вы хотите делать анимацию:

sizeX = button1.getParent().getLayoutBounds().getWidth();
sizeY = button1.getParent().getLayoutBounds().getHeight(); 

В данном случае это родительский элемент для button1, но так можно определить размеры любой подложки.

READ ALSO
Перевод большого числа в byte

Перевод большого числа в byte

Делаю шифрование с помощью сдвигов битов в байтеНо если байту присвоить значение больше 127, оно начинает терять данные

128
Бинарные деревья и изоморфность

Бинарные деревья и изоморфность

Лучший источник в данном примере указано, что

157
Запуск .jar файлов на линукс

Запуск .jar файлов на линукс

Не могу запустить программуjar формата в терминале, и в графическом интерфейсе

140