我创建了一个TabPane,其中有4个标签,每个标签中都有按钮。每次我运行我的应用程序时,在第一次运行时它总是显示我已经按下了“维护问题”。标签当然不是真的Like in this picture。如何更改它,以便在打开应用程序时它不会从选项卡中显示任何内容? 我是用场景构建器做的,所以这里是我的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>
答案 0 :(得分:0)
如果没有很多'hacky workarounds',我认为这是不可能的。虽然从图片看起来你似乎将它用作Menu
?那你为什么不试试MenuBar
而不是TabPane
?
以下是MenuBars上的一个不错的tutorial,可能会帮助您入门。