JAVA - JavaFX - 处理调用另一个阶段的节点例如:JButton

问题描述

我想要一个主舞台(主 GUI),它在顶部包含一个菜单栏,然后​​由一个带有垂直 SplitPane 的 AnchorPane 组成[拆分发生在 350 像素](右侧包含另一个水平 SplitPane ,总共给我 3 个部分来使用),或者只使用 borderpane 的 Left、Top 和 Center 的 borderpane。在垂直 SplitPane(或 Left borderpane)中,我想要 3 个按钮,它们占用大约 320x320 像素,留下一个 15 像素的缓冲区。 Top 部分[200 像素高度xMaxValue 宽度] 将有一个背景图像、一个ImageView 和一个标签。现在,borderpane 的中心部分,或第一个 SplitPane 的右侧,其中包含一个水平 SplitPane,即参考该 SplitPane 的底部,将是最大的区域。我想在那个区域有 5 个按钮,[我可以调整这些按钮的大小和间距,可能在水平 Splitpane 的底部使用一个 GridPane],当单击左侧的第一个按钮时,它将变得可见。然后我想在单击第二个按钮时显示另外 5 个不同的按钮,删除前 5 个按钮。我不知道我是否需要让左侧的按钮调用 GridPane 5 个按钮可见,或者如何设置它。然后我希望 GridPane 中的按钮调用一个 Stage(实际上是 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.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...