Максимизация панелей в Javafx - PullRequest
0 голосов
/ 13 марта 2020

Я играл и тестировал с JavaFX, но одной проблемой, с которой я столкнулся, было увеличение размера панели. Я установил размер области привязки, чтобы использовать вычисленный размер, но он никогда не изменяет размеры и ничего не делает. Моя панель является фиксированной и не может изменять размеры. Могу ли я что-нибудь сделать, чтобы изменить размер панели? Спасибо! Я проверил размеры моего макета, но они были исправлены, хотя я установил размеры на расчетный размер. Прямо сейчас мой проект имеет только файлы F XML и некоторые методы в классе контроллера, которые еще ничего не делают.

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

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<AnchorPane fx:id="homePane" prefHeight="576.0" prefWidth="1050.0" style="-fx-background-color: #02030A;" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
    <children>
        <VBox alignment="TOP_CENTER" prefHeight="576.0" prefWidth="256.0" style="-fx-background-color: #FA674E#FA674E;" AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="0.0">
            <children>
                <ImageView fitHeight="210.0" fitWidth="227.0" pickOnBounds="true" preserveRatio="true">
                    <image>
                        <Image url="@../sample/images/unnamed.png" />
                    </image>
                    <VBox.margin>
                        <Insets bottom="10.0" top="50.0" />
                    </VBox.margin></ImageView>
                <Label text="Calorie Tracker Portal" textFill="WHITE">
                    <VBox.margin>
                        <Insets bottom="20.0" />
                    </VBox.margin>
                    <font>
                        <Font name="System Bold" size="24.0" />
                    </font>
                </Label>
                <Button fx:id="homeButton" alignment="BASELINE_LEFT" graphicTextGap="22.0" mnemonicParsing="false" onAction="#loadHome" prefHeight="140.0" prefWidth="256.0" style="-fx-background-color: #FA674E#FA674E;" text="Home" textFill="WHITE">
                    <graphic>
                        <ImageView fitHeight="23.0" fitWidth="27.0" pickOnBounds="true" preserveRatio="true">
                            <image>
                                <Image url="@../sample/images/icons8_Home_32px.png" />
                            </image>
                        </ImageView>
                    </graphic>
                    <opaqueInsets>
                        <Insets />
                    </opaqueInsets>
                    <VBox.margin>
                        <Insets />
                    </VBox.margin>
                    <padding>
                        <Insets left="50.0" />
                    </padding>
                </Button>
                <Button fx:id="tipsButton" alignment="BASELINE_LEFT" graphicTextGap="22.0" mnemonicParsing="false" onAction="#loadTips" prefHeight="140.0" prefWidth="256.0" style="-fx-background-color: #FA674E#FA674E;" text="Tips" textFill="WHITE">
                    <graphic>
                        <ImageView fitHeight="26.0" fitWidth="28.0" pickOnBounds="true" preserveRatio="true">
                            <image>
                                <Image url="@../sample/images/icons8_Open_Envelope_32px.png" />
                            </image>
                        </ImageView>
                    </graphic>
                    <padding>
                        <Insets left="50.0" />
                    </padding>
                </Button>
            </children>
        </VBox>
        <StackPane layoutX="258.0" prefHeight="576.0" prefWidth="793.0" style="-fx-background-color: #02030A;">
            <children>
                <Pane prefHeight="200.0" prefWidth="200.0" />
                <Pane fx:id="pnlOrders" prefHeight="200.0" prefWidth="200.0" />
                <Pane fx:id="pnlMenus" prefHeight="200.0" prefWidth="200.0" />
                <Pane fx:id="exit" style="-fx-background-color: #1b262c#1b262c;">
                    <children>
                        <TextField fx:id="searchFood" layoutX="590.0" layoutY="47.0" prefHeight="27.0" prefWidth="183.0" promptText="Search Food" style="-fx-background-color: #1b262c#1b262c; -fx-border-color: #B7C3D7; -fx-border-radius: 2em;" />
                        <Label layoutX="26.0" layoutY="25.0" prefHeight="29.0" prefWidth="183.0" text="Calorie Tracker" textFill="#e7e5e5">
                            <font>
                                <Font size="24.0" />
                            </font>
                        </Label>
                        <HBox alignment="CENTER_LEFT" layoutX="45.0" layoutY="72.0" prefHeight="92.0" prefWidth="661.0" spacing="50.0">
                            <children>
                                <VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0">
                                    <children>
                                        <Label fx:id="totalCalories" text="N/A" textFill="#2a73ff">
                                            <font>
                                                <Font name="System Bold" size="26.0" />
                                            </font>
                                        </Label>
                                        <Label prefHeight="20.0" prefWidth="81.0" text="Total Calories" textFill="#e7e5e5" />
                                    </children>
                                </VBox>
                                <VBox alignment="CENTER" prefHeight="92.0" prefWidth="105.0">
                                    <children>
                                        <Label fx:id="weeklyCalories" text="N/A" textFill="#26bfbc">
                                            <font>
                                                <Font name="System Bold" size="26.0" />
                                            </font>
                                        </Label>
                                        <Label text="Weekly Calories" textFill="#e7e5e5" />
                                    </children>
                                </VBox>
                                <VBox alignment="CENTER" prefHeight="92.0" prefWidth="98.0">
                                    <children>
                                        <Label fx:id="AverageCalories" text="N/A" textFill="#fa5f7e">
                                            <font>
                                                <Font name="System Bold" size="26.0" />
                                            </font>
                                        </Label>
                                        <Label prefHeight="20.0" prefWidth="100.0" text="Average Calories" textFill="#e7e5e5" textOverrun="CLIP" />
                                    </children>
                                </VBox>
                                <VBox alignment="CENTER" prefHeight="92.0" prefWidth="98.0">
                                    <children>
                                        <Label fx:id="foodEaten" text="N/A" textFill="#de0000">
                                            <font>
                                                <Font name="System Bold" size="26.0" />
                                            </font>
                                        </Label>
                                        <Label prefWidth="100.0" text="# of food eaten" textFill="#e7e5e5" textOverrun="CLIP" />
                                    </children>
                                </VBox>
                            </children>
                        </HBox>
                        <ScrollPane layoutX="14.0" layoutY="232.0" prefHeight="320.0" prefWidth="746.0">
                            <content>
                                <VBox prefHeight="318.0" prefWidth="744.0" spacing="5.0" style="-fx-background-color: #02030A;">
                                    <padding>
                                        <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
                                    </padding>
                                    <children>
                                        <TableView fx:id="tableView" prefHeight="315.0" prefWidth="734.0" style="-fx-background-color: #1b262c#1b262c #1b262c#1b262c;">
                                            <columns>
                                                <TableColumn fx:id="food" prefWidth="239.0" text="Food" />
                                                <TableColumn fx:id="calories" prefWidth="249.0" text="Calories" />
                                                <TableColumn fx:id="date" prefWidth="75.0" text="Date" />
                                            </columns>
                                            <columnResizePolicy>
                                                <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
                                            </columnResizePolicy>
                                        </TableView>
                                    </children>
                                </VBox>
                            </content>
                        </ScrollPane>
                        <ImageView fitHeight="17.0" fitWidth="16.0" layoutX="749.0" layoutY="53.0" pickOnBounds="true" preserveRatio="true">
                            <image>
                                <Image url="@../sample/images/icons8_Search_52px.png" />
                            </image>
                        </ImageView>
                        <HBox alignment="CENTER_LEFT" layoutX="14.0" layoutY="162.0" prefHeight="70.0" prefWidth="778.0" spacing="50.0">
                            <children>
                                <VBox alignment="CENTER" prefHeight="161.0" prefWidth="148.0">
                                    <children>
                                        <Button fx:id="instructionButton" mnemonicParsing="false" onAction="#loadInstructions" prefHeight="20.0" prefWidth="124.0" style="-fx-background-color: #2a73ff#2a73ff;" text="Instructions" textFill="WHITE" />
                                        <Label textFill="#e7e5e5" />
                                    </children>
                                </VBox>
                                <VBox alignment="CENTER" prefHeight="92.0" prefWidth="98.0">
                                    <children>
                                        <Button fx:id="editButton" mnemonicParsing="false" onAction="#editPopup" prefHeight="27.0" prefWidth="90.0" style="-fx-background-color: #26bfbc#26bfbc;" text="Edit" textFill="WHITE" />
                                        <Label prefHeight="0.0" prefWidth="98.0" textFill="#e7e5e5" textOverrun="CLIP" />
                                    </children>
                                </VBox>
                                <VBox alignment="CENTER" prefHeight="144.0" prefWidth="97.0">
                                    <children>
                                        <Button fx:id="addFood" mnemonicParsing="false" onAction="#addFoodButton" prefHeight="27.0" prefWidth="163.0" style="-fx-background-color: #2a73ff#2a73ff;" text="Add Food" textFill="WHITE" />
                                        <Label prefHeight="0.0" prefWidth="97.0" textFill="#e7e5e5" textOverrun="CLIP" />
                                    </children>
                                </VBox>
                                <VBox alignment="CENTER" prefHeight="92.0" prefWidth="98.0">
                                    <children>
                                        <Button fx:id="deleteFood" mnemonicParsing="false" onAction="#deleteFoodButton" prefHeight="1.0" prefWidth="97.0" style="-fx-background-color: #fa5f7e#fa5f7e;" text="Delete food" textFill="WHITE" />
                                        <Label prefHeight="0.0" prefWidth="98.0" textFill="#e7e5e5" textOverrun="CLIP" />
                                    </children>
                                </VBox>
                                <VBox alignment="CENTER" prefHeight="74.0" prefWidth="79.0">
                                    <children>
                                        <Label text="Sort by.." textFill="WHITE" />
                                        <Region prefHeight="9.0" prefWidth="100.0" />
                                        <MenuButton fx:id="selectSort" mnemonicParsing="false" style="-fx-background-color: #de0000#de0000;">
                                            <items>
                                                <MenuItem mnemonicParsing="false" text="Action 1" />
                                                <MenuItem mnemonicParsing="false" text="Action 2" />
                                            </items>
                                        </MenuButton>
                                    </children>
                                </VBox>
                                <VBox alignment="CENTER" prefHeight="92.0" prefWidth="98.0" />
                            </children>
                        </HBox>
                    </children>
                </Pane>
            </children>
        </StackPane>
    </children>
    <effect>
        <DropShadow color="#1b1eeb" />
    </effect>
</AnchorPane>
package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}
...