0

我想要一个主舞台(主 GUI),它将在顶部包含一个菜单栏,然后​​由一个带有垂直 SplitPane [拆分发生在 350 像素] 的 AnchorPane 组成(它在右侧包含另一个水平 SplitPane,给了我总共有 3 个部分可供使用),或者一个仅使用 BorderPane 的 Left、Top 和 Center 的 BorderPane。在垂直的 SplitPane(或 Left BorderPane)中,我想要 3 个占用大约 320x320 像素的按钮,留下一个 15 像素的缓冲区。顶部部分[200 像素高度xMaxValue 宽度] 将有一个背景图像、一个 ImageView 和一个标签。现在 BorderPane 的中心部分,或第一个 SplitPane 的右侧,其中包含一个水平的 SplitPane,即该 SplitPane 的底部,将是最大的区域。我想在那个区域有5个按钮,[我可以调整这些按钮的大小和间距,可能在水平拆分窗格的底部使用 GridPane] 当单击左侧的第一个按钮时,它将变得可见。然后我希望在单击第二个按钮时显示另外 5 个不同的按钮,删除前 5 个按钮。我不知道是否需要让左侧的按钮调用 GridPane 中的 5 个按钮可见,或者如何设置它。然后我希望 GridPane 中的按钮调用另一个阶段(实际上是 5 个单独的阶段,但一次可见一个),它在打开时覆盖整个第一个阶段。另外,我需要将其调整为打开最大化的默认尺寸 1440x900(最小尺寸)。(我可以处理那个功能,我只需要子节点来调整它的大小,但只有一个大小。我需要第一个拆分窗格的左侧仅调整高度,顶部部分仅调整宽度。我知道,这很多,但我试图提供尽可能多的信息。感谢大家对此的帮助。

这是到目前为止的代码:

javaFX

package scindbmain;

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

public class MainGUI extends Application {


    @Override
    public void start(Stage primaryStage) throws Exception {
        Parent rootPane = FXMLLoader.load(getClass().getResource("maingui.fxml"));
        Scene scene = new Scene(rootPane);
        primaryStage.setTitle("Star Citizen InfoNet & Database");
        primaryStage.setScene(scene);
        primaryStage.setMinWidth(1440);
        primaryStage.setMinHeight(900);
        primaryStage.setMaximized(true);
        primaryStage.setResizable(false);
        primaryStage.show();
    }

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

     }
}

And here is my FXML file to go with it:

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

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

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="900.0" prefWidth="1440.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <MenuBar maxHeight="25.0" minHeight="25.0" prefHeight="25.0" style="-fx-background-color: beige;" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <menus>
          <Menu mnemonicParsing="false" text="File">
            <items>
              <MenuItem mnemonicParsing="false" text="Close" />
            </items>
          </Menu>
          <Menu mnemonicParsing="false" text="Edit">
            <items>
              <MenuItem mnemonicParsing="false" text="Delete" />
            </items>
          </Menu>
          <Menu mnemonicParsing="false" text="Help">
            <items>
              <MenuItem mnemonicParsing="false" text="About" />
            </items>
          </Menu>
        </menus>
      </MenuBar>
      <SplitPane dividerPositions="0.18567454798331015" layoutY="29.0" prefHeight="900.0" prefWidth="1440.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="25.0">
        <items>
            <VBox maxWidth="350.0" minHeight="-Infinity" minWidth="350.0" prefHeight="875.0" prefWidth="350.0" spacing="30.0" style="-fx-background-color: grey;">
               <children>
                  <Button maxHeight="300.0" maxWidth="300.0" minHeight="300.0" minWidth="300.0" mnemonicParsing="false" prefHeight="300.0" prefWidth="300.0" style="-fx-background-color: silver;" text="Star Systems &amp; Locations" textAlignment="CENTER" wrapText="true">
                     <font>
                        <Font name="Impact" size="45.0" />
                     </font>
                     <VBox.margin>
                        <Insets />
                     </VBox.margin>
                  </Button>
                  <Button layoutX="25.0" layoutY="25.0" maxHeight="300.0" maxWidth="300.0" minHeight="300.0" minWidth="300.0" mnemonicParsing="false" prefHeight="300.0" prefWidth="300.0" style="-fx-background-color: silver;" text="Starships, Weapons &amp; Components" textAlignment="CENTER" wrapText="true">
                     <font>
                        <Font name="Impact" size="45.0" />
                     </font>
                     <VBox.margin>
                        <Insets />
                     </VBox.margin>
                  </Button>
                  <Button layoutX="25.0" layoutY="375.0" maxHeight="300.0" maxWidth="300.0" minHeight="300.0" minWidth="300.0" mnemonicParsing="false" prefHeight="300.0" prefWidth="300.0" style="-fx-background-color: silver;" text="Trading, Mining &amp; Refining" textAlignment="CENTER" wrapText="true">
                     <font>
                        <Font name="Impact" size="45.0" />
                     </font>
                     <VBox.margin>
                        <Insets />
                     </VBox.margin>
                  </Button>
               </children>
               <padding>
                  <Insets bottom="15.0" left="25.0" right="15.0" top="15.0" />
               </padding>
            </VBox>
            <SplitPane dividerPositions="0.22451317296678122" orientation="VERTICAL" prefHeight="200.0" prefWidth="160.0">
              <items>
                  <HBox maxHeight="200.0" minHeight="200.0" minWidth="1090.0" prefHeight="200.0" prefWidth="1090.0" spacing="25.0" style="-fx-background-color: black;">
                     <padding>
                        <Insets bottom="10.0" left="15.0" top="10.0" />
                     </padding>
                     <children>
                        <ImageView fitHeight="180.0" fitWidth="180.0" pickOnBounds="true" HBox.hgrow="NEVER">
                           <image>
                              <Image url="@../SCImages/TaktikalLogo1.jpg" />
                           </image>
                        </ImageView>
                        <Label minWidth="1000.0" prefHeight="180.0" prefWidth="1000.0" style="-fx-border-color: white;" text="STAR CITIZEN INFONET &amp; DATABASE" textAlignment="CENTER" textFill="WHITE" wrapText="true">
                           <HBox.margin>
                              <Insets bottom="10.0" top="10.0" />
                           </HBox.margin>
                           <font>
                              <Font name="Mongolian Baiti" size="68.0" />
                           </font>
                        </Label>
                     </children>
                  </HBox>
                <AnchorPane minHeight="668.0" minWidth="1090.0" prefHeight="338.0" prefWidth="1090.0">
                     <children>
                        <StackPane prefHeight="668.0" prefWidth="1090.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                           <children>
                              <GridPane>
                                <columnConstraints>
                                    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                                  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                                  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                                </columnConstraints>
                                <rowConstraints>
                                  <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                                  <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                                </rowConstraints>
                              </GridPane>
                           </children>
                        </StackPane>
                     </children></AnchorPane>
              </items>
            </SplitPane>
        </items>
      </SplitPane>
   </children>
</AnchorPane>
Now, as you can see I have coded some of the GUI. And I have 3 buttons on the left side. I want to have each of those buttons call a Pane(AnchorPane,StackPane, i dont know which one) to fill the bottom right of my Stage (bottom half of the horizontal StackPane) with 5 buttons on each pane. Each button will call a different Pane with 5 different buttons that will each call a different stage. But for now, I have problems with the GUI. I have it set to Maximum because if i set it to 1440x900, and set it to not resize, it will still let me resize it down a little bit, and it moves the GUI out of place. I don't think this code is the correct code to do this with, which is why I was asking for someone's example earlier, instead of putting this code up. Thank you for any help.
4

0 回答 0