Как я могу делать динамические макеты в Javafx? - PullRequest
0 голосов
/ 07 июня 2019

Прежде всего, извините, если мой английский плохой, я не говорю по-английски. Итак, я работаю с javafx, когда я говорю «динамические макеты», я имею в виду тот факт, что мой .fxml уже запрограммирован со структурой по умолчанию, что так и есть. menu.fxml view и его код это

<?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXButton?>
<?import java.lang.String?>
<?import java.net.URL?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<AnchorPane prefWidth="356.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <VBox prefHeight="243.0" prefWidth="356.0" spacing="2.0" stylesheets="@../styles/Containers.css" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <children>
            <AnchorPane prefHeight="31.0" prefWidth="356.0">
               <children>
                  <HBox prefHeight="35.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                     <padding>
                        <Insets bottom="8.0" top="8.0" />
                     </padding>
                     <children>
                        <ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true">
                           <HBox.margin>
                              <Insets left="10.0" />
                           </HBox.margin>
                           <image>
                              <Image url="@../icons/icons8_Calendar_100px.png" />
                           </image>
                        </ImageView>
                        <Label fx:id="lblFecha" prefHeight="31.0" prefWidth="306.0" stylesheets="@../styles/Strings.css" text="---- ----, -----">
                           <HBox.margin>
                              <Insets left="15.0" />
                           </HBox.margin>
                           <styleClass>
                              <String fx:value="h4" />
                              <String fx:value="principal" />
                           </styleClass>
                        </Label>
                     </children>
                  </HBox>
               </children>
            </AnchorPane>
            <AnchorPane>
               <children>
                  <HBox prefHeight="35.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                     <children>
                        <ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true">
                           <image>
                              <Image url="@../icons/icons8_Clock_100px.png" />
                           </image>
                           <HBox.margin>
                              <Insets left="10.0" />
                           </HBox.margin>
                        </ImageView>
                        <Label fx:id="lblHora" prefHeight="31.0" prefWidth="306.0" stylesheets="@../styles/Strings.css" text="-- : -- : -- --">
                           <HBox.margin>
                              <Insets left="15.0" />
                           </HBox.margin>
                           <styleClass>
                              <String fx:value="h4" />
                              <String fx:value="principal" />
                           </styleClass>
                        </Label>
                     </children>
                     <padding>
                        <Insets bottom="8.0" top="8.0" />
                     </padding>
                  </HBox>
               </children>
            </AnchorPane>
            <AnchorPane fx:id="opcParlking">
               <children>
                  <JFXButton alignment="BASELINE_LEFT" graphicTextGap="25.0" onAction="#openParking" prefHeight="35.0" prefWidth="366.0" styleClass="h4" text="Parking" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                     <graphic>
                        <ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true" translateX="10.0">
                           <image>
                              <Image url="@../icons/icons8_Tollbooth_100px.png" />
                           </image>
                        </ImageView>
                     </graphic>
                     <font>
                        <Font name="System Bold" size="12.0" />
                     </font>
                     <padding>
                        <Insets bottom="8.0" top="8.0" />
                     </padding>
                     <stylesheets>
                        <URL value="@../styles/Buttons.css" />
                        <URL value="@../styles/Strings.css" />
                     </stylesheets>
                  </JFXButton>
               </children>
            </AnchorPane>
            <AnchorPane>
               <children>
                  <JFXButton alignment="BASELINE_LEFT" graphicTextGap="25.0" prefHeight="35.0" prefWidth="363.0" styleClass="h4" text="Tipo de vehiculos" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                     <graphic>
                        <ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true" translateX="10.0">
                           <image>
                              <Image url="@../icons/icons8_Traffic_Jam_96px.png" />
                           </image>
                        </ImageView>
                     </graphic>
                     <font>
                        <Font name="System Bold" size="12.0" />
                     </font>
                     <padding>
                        <Insets bottom="8.0" top="8.0" />
                     </padding>
                     <stylesheets>
                        <URL value="@../styles/Buttons.css" />
                        <URL value="@../styles/Strings.css" />
                     </stylesheets>
                  </JFXButton>
               </children>
            </AnchorPane>
            <AnchorPane>
               <children>
                  <JFXButton alignment="BASELINE_LEFT" graphicTextGap="25.0" prefHeight="35.0" prefWidth="363.0" styleClass="h4" text="Usuarios" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                     <graphic>
                        <ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true" translateX="10.0">
                           <image>
                              <Image url="@../icons/icons8_User_Groups_100px.png" />
                           </image>
                        </ImageView>
                     </graphic>
                     <font>
                        <Font name="System Bold" size="12.0" />
                     </font>
                     <padding>
                        <Insets bottom="8.0" top="8.0" />
                     </padding>
                     <stylesheets>
                        <URL value="@../styles/Buttons.css" />
                        <URL value="@../styles/Strings.css" />
                     </stylesheets>
                  </JFXButton>
               </children>
            </AnchorPane>
            <AnchorPane>
               <children>
                  <JFXButton alignment="BASELINE_LEFT" graphicTextGap="25.0" prefHeight="35.0" prefWidth="361.0" styleClass="h4" text="Clientes" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                     <graphic>
                        <ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true" translateX="10.0">
                           <image>
                              <Image url="@../icons/icons8_Helping_Hand_104px.png" />
                           </image>
                        </ImageView>
                     </graphic>
                     <font>
                        <Font name="System Bold" size="12.0" />
                     </font>
                     <padding>
                        <Insets bottom="8.0" top="8.0" />
                     </padding>
                     <stylesheets>
                        <URL value="@../styles/Buttons.css" />
                        <URL value="@../styles/Strings.css" />
                     </stylesheets>
                  </JFXButton>
               </children>
            </AnchorPane>
            <AnchorPane>
               <children>
                  <JFXButton alignment="BASELINE_LEFT" graphicTextGap="25.0" prefHeight="35.0" prefWidth="361.0" styleClass="h4" text="Reportes" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                     <graphic>
                        <ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true" translateX="10.0">
                           <image>
                              <Image url="@../icons/icons8_Combo_Chart_104px.png" />
                           </image>
                        </ImageView>
                     </graphic>
                     <font>
                        <Font name="System Bold" size="12.0" />
                     </font>
                     <padding>
                        <Insets bottom="8.0" top="8.0" />
                     </padding>
                     <stylesheets>
                        <URL value="@../styles/Buttons.css" />
                        <URL value="@../styles/Strings.css" />
                     </stylesheets>
                  </JFXButton>
               </children>
            </AnchorPane>
            <AnchorPane>
               <children>
                  <JFXButton alignment="BASELINE_LEFT" graphicTextGap="25.0" prefHeight="29.0" prefWidth="356.0" styleClass="h4" text="Configuraciones" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                     <graphic>
                        <ImageView fitHeight="25.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true" translateX="10.0">
                           <image>
                              <Image url="@../icons/icons8_Automation_100px.png" />
                           </image>
                        </ImageView>
                     </graphic>
                     <font>
                        <Font name="System Bold" size="12.0" />
                     </font>
                     <padding>
                        <Insets bottom="8.0" top="8.0" />
                     </padding>
                     <stylesheets>
                        <URL value="@../styles/Buttons.css" />
                        <URL value="@../styles/Strings.css" />
                     </stylesheets>
                  </JFXButton>
               </children>
            </AnchorPane>
         </children>
      </VBox>
   </children>
</AnchorPane>

Я хочу, чтобы во время выполнения я мог скрыть любые кнопки и чтобы эти кнопки автоматически настраивались, заполняя пустое пространство, оставленное скрытой кнопкой.

Я пытался использовать в MenuController.java инструкции, такие как opcParlking.setVisible(false), но это оставило мне пустое место. Это картинка Imagen 2 . Как я могу это исправить?

1 Ответ

2 голосов
/ 07 июня 2019

Вы также захотите присвоить fx:id своему VBox, а затем ввести его в свой контроллер:

@FXML
private VBox vBox;

Затем в вашем контроллере вместо установки видимого узла или нет просто удалите его из VBox:

vBox.getChildren().remove(opcParlking);

Это полностью удалит узел, а не сделает его невидимым. Поэтому у вас не будет пустого места.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...