首页 > 解决方案 > JavaFX - TitledPane 没有在 TitledPane 标题图形中显示 JFXButton 文本

问题描述

我正在使用 Accordion TitledPane 制作侧边栏菜单,每当我在 TitledPane 的标题图形中添加 JFXButton 时,它都非常适合其中但按钮文本没有显示。我在按钮内添加了 fontAwesomeIcon,我可以看到 fontAwesome Icon 但看不到按钮文本。此外,当 TiledPane 展开 JFXButton 文本时也不会显示。

下面是我的 FXML 代码

<VBox layoutY="76.0" maxWidth="-Infinity" prefHeight="664.0" prefWidth="250.0" style="-fx-background-color: #E5DEF3;" AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="76.0">
         <children>
            <ImageView fitHeight="40.0" fitWidth="250.0" pickOnBounds="true" preserveRatio="true" />
            <Accordion nodeOrientation="RIGHT_TO_LEFT">
              <panes>
                <TitledPane fx:id="tt1" alignment="CENTER_RIGHT" cache="true" contentDisplay="GRAPHIC_ONLY" graphicTextGap="4.0">
                     <graphic>
                        <JFXButton fx:id="ttbtn1" alignment="CENTER_RIGHT" contentDisplay="RIGHT" graphicTextGap="10.0" maxWidth="1.7976931348623157E308" prefHeight="40.0" prefWidth="218.0">
                           <graphic>
                              <FontAwesomeIconView size="1.5em" />
                           </graphic>
                           <font>
                              <Font size="14.0" />
                           </font>
                        </JFXButton>
                     </graphic>
                     <content>
                        <VBox alignment="TOP_CENTER" prefWidth="100.0">
                           <children>
                              <JFXButton alignment="CENTER" prefHeight="36.0" prefWidth="271.0" />
                              <JFXButton alignment="CENTER" prefHeight="36.0" prefWidth="271.0" />
                              <JFXButton alignment="CENTER" prefHeight="36.0" prefWidth="271.0" />
                              <JFXButton alignment="CENTER" prefHeight="36.0" prefWidth="271.0" />
                              <JFXButton alignment="CENTER" prefHeight="36.0" prefWidth="271.0" />
                           </children>
                        </VBox>
                     </content>
                </TitledPane>
                <TitledPane alignment="CENTER_RIGHT" contentDisplay="GRAPHIC_ONLY" text="untitled 2">
                  <content>
                    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                  </content>
                     <graphic>
                        <JFXButton alignment="CENTER_RIGHT" contentDisplay="RIGHT" graphicTextGap="10.0" maxWidth="1.7976931348623157E308" prefHeight="40.0" prefWidth="217.0">
                           <graphic>
                              <FontAwesomeIconView glyphName="HOME" size="1.5em" />
                           </graphic>
                           <font>
                              <Font size="14.0" />
                           </font>
                        </JFXButton>
                     </graphic>
                </TitledPane>
                <TitledPane alignment="CENTER_RIGHT" contentDisplay="GRAPHIC_ONLY" text="untitled 3">
                  <content>
                    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                  </content>
                     <graphic>
                        <JFXButton alignment="CENTER_RIGHT" contentDisplay="RIGHT" graphicTextGap="10.0" maxWidth="1.7976931348623157E308" prefHeight="40.0" prefWidth="215.0">
                           <graphic>
                              <FontAwesomeIconView glyphName="HOME" size="1.5em" />
                           </graphic>
                           <font>
                              <Font size="14.0" />
                           </font>
                        </JFXButton>
                     </graphic>
                </TitledPane>
              </panes>
            </Accordion>
         </children>
      </VBox>

我想要这样的输出

在此处输入图像描述

我得到的是

在此处输入图像描述

在 Scene Builder 中,所有组件都正确显示,但是当我运行带有 netbeans 按钮文本的项目时没有呈现。请帮助我实现所需的输出。

标签: javajavafxjavafx-8accordion

解决方案


推荐阅读