简体   繁体   English

打开应用程序时,在Tabpane Javafx中更改选项视图

[英]Change options view in tabpane javafx when opening the application

I created a TabPane that has 4 tabs in it and each tab has buttons in it. 我创建了一个TabPane,其中有4个选项卡,每个选项卡中都有按钮。 Every time I run my application, at the first run it always shows like I already pressed on the 'Maintain Questions' tab which is of course not true Like in this picture . 每次我运行我的应用程序时,在第一次运行时,它总是显示出我已经按过'Maintain Questions'选项卡上的样子,这当然不是真的, 就像这张图片所示 How can I change it that it will show me nothing from the tabs when I open the application? 我如何更改它,以使其在打开应用程序时不会显示选项卡上的任何内容? I did it with the scene builder so here is my fxml code: 我是使用场景生成器完成的,因此这是我的fxml代码:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane fx:id="anchorPane" focusTraversable="false" prefHeight="570.0" prefWidth="861.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.TeacherWindowController">
   <children>
      <ImageView fitHeight="669.0" fitWidth="985.0" focusTraversable="true" pickOnBounds="true">
         <image>
            <Image url="@../bigstock-Stack-Of-Books-70033240.jpg" />
         </image>
      </ImageView>
      <Text fx:id="welcomeText" fill="WHITE" layoutX="14.0" layoutY="40.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Welcome" wrappingWidth="370.0">
         <font>
            <Font size="24.0" />
         </font></Text>
      <Text fx:id="TextGroup7" layoutX="365.0" layoutY="664.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Copyright © 2018 Group7" />
      <ImageView fx:id="Group7Logo" blendMode="MULTIPLY" fitHeight="150.0" fitWidth="200.0" layoutX="348.0" layoutY="572.0" pickOnBounds="true" preserveRatio="true">
         <image>
            <Image url="@../logo.jpg" />
         </image>
      </ImageView>
      <Text fx:id="date" fill="#fffdfd" layoutX="831.0" layoutY="39.0" strokeType="OUTSIDE" strokeWidth="0.0" wrappingWidth="140.0">
         <font>
            <Font size="24.0" />
         </font>
      </Text>
      <Button fx:id="addQuestiton" layoutX="298.0" layoutY="85.0" mnemonicParsing="false" prefHeight="31.0" prefWidth="173.0" text="Add Question" visible="false" />
      <Button fx:id="editOrRemoveQuestion" layoutX="298.0" layoutY="116.0" mnemonicParsing="false" prefHeight="31.0" prefWidth="173.0" text="Edit/Remove Question" visible="false" />
      <Button fx:id="logoutButton" layoutX="910.0" layoutY="52.0" mnemonicParsing="false" onAction="#logOutButtonHandler" text="Logout" />
      <TabPane fx:id="tabPane" focusTraversable="false" layoutX="13.0" layoutY="44.0" nodeOrientation="LEFT_TO_RIGHT" pickOnBounds="false" prefHeight="145.0" prefWidth="533.0" style="-fx-focus-traversable: false;" styleClass="TeacherWindow.css" stylesheets="@TeacherWindow.css" tabClosingPolicy="UNAVAILABLE">
        <tabs>
          <Tab closable="false" text="Maintain Questions">
            <content>
              <AnchorPane minHeight="0.0" minWidth="0.0" nodeOrientation="LEFT_TO_RIGHT" pickOnBounds="false" prefHeight="116.0" prefWidth="146.0" stylesheets="">
                     <children>
                        <Button focusTraversable="false" layoutX="-10.0" layoutY="31.0" mnemonicParsing="false" pickOnBounds="false" prefHeight="32.0" prefWidth="173.0" text="Edit/Remove Question" />
                        <Button focusTraversable="false" layoutX="-10.0" mnemonicParsing="false" pickOnBounds="false" prefHeight="31.0" prefWidth="173.0" text="Add Question" />
                     </children>
                  </AnchorPane>
            </content>
          </Tab>
          <Tab text="Maintain Exams">
            <content>
              <AnchorPane focusTraversable="false" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
            </content>
          </Tab>
            <Tab text="Order Reports">
              <content>
                <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
              </content>
            </Tab>
            <Tab text="Confirm Grades">
              <content>
                <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="106.0" prefWidth="763.0" />
              </content>
            </Tab>
        </tabs>
      </TabPane>
   </children>
</AnchorPane>

I dont think that is possible without a lot of 'hacky workarounds'. 我认为如果没有很多“棘手的解决方法”,这是不可能的。 Though from the Picture it seems like you use it as a Menu ? 虽然从图片看来好像您将其用作Menu So why don't you try the MenuBar instead of a TabPane ? 那么,为什么不尝试使用MenuBar而不是TabPane呢?

Here is a nice tutorial on MenuBars which might help you get started. 这是一个关于MenuBars的不错的教程 ,可能会帮助您入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM