JavaFX/FXML: ImageView 和 BorderPane 内的标签不显示

JavaFX/FXML: ImageView and labels inside BorderPane not displayed

我的问题是,在以下构造中,未显示...中的 GridPane 内的 BorderPane 内的粗体标记图像和标签。我将图像和标签放在另一个 BorderPane 中,这样 GridPane 的每一行都有更多样式选项。当只有一些标签在 BorderPane 内时,所有标签(包括它们本身和 BorderPane 内的标签)都会显示,但现在所有标签都在各自的 BorderPanes 内,显示 none。为 BorderPanes 设置 prefHeight 没有任何区别。有什么想法吗?

编辑:将某些内容标记为粗体似乎在代码字段中不起作用。我说的是 GridPane.rowIndex="0".

上的所有内容

提前致谢!

example.fxml

<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.TilePane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.control.CheckBox?>

<BorderPane fx:controller="examplePackage.exampleController" xmlns:fx="http://javafx.com/fxml">

<VBox>
    <TitledPane>
<!-- ................................................................................... -->
        <graphic>
            <BorderPane prefWidth="1312">
                <left>
                    <BorderPane>
                        <left>
                            <ImageView>
                                <Image url="file:///....png"/>
                            </ImageView>
                        </left>
                        <right>
                            <Label text="Text" style="-fx-padding:5"></Label>
                        </right>
                    </BorderPane>
                </left>
                <center> 
                </center>
                <right>
                    <BorderPane>
                        <left>
                            <StackPane prefWidth="32">
                                <ImageView>
                                    <Image url="file:///....png"/>
                                </ImageView>
                            </StackPane>
                        </left>
                        <right>
                            <StackPane prefWidth="28" style="-fx-padding:0,5,0,5; -fx-border-width:0px 0px 0px 0.5px; -fx-border-style: solid; -fx-border-color:#ffffff">
                                <ImageView>
                                    <Image url="file:///....png"/>
                                </ImageView>
                            </StackPane>
                        </right>
                    </BorderPane>
                </right>
            </BorderPane>
        </graphic>
<!-- ................................................................................... -->
        <GridPane>
            <columnConstraints>
                <ColumnConstraints percentWidth="5.0"/>
                <ColumnConstraints percentWidth="25.0"/>
                <ColumnConstraints percentWidth="25.0"/>
                <ColumnConstraints percentWidth="25.0"/>
                <ColumnConstraints percentWidth="20.0"/>
            </columnConstraints>

            <BorderPane prefHeight="30" GridPane.rowIndex="0" GridPane.columnIndex="0" style="-fx-border-color: rgb(0,0,0); -fx-border-width:0px 0px 0.5px 0px">
                <ImageView>
                    <Image url="file:///....png"/>
                </ImageView>
            </BorderPane>

            <BorderPane GridPane.rowIndex="0" GridPane.columnIndex="1" style="-fx-border-color: rgb(0,0,0); -fx-border-width:0px 0px 0.5px 0px">
            <Label text="Text">
                <font>
                <Font name="Arial" size="13"></Font>
                </font>
            </Label>
            </BorderPane>

            <BorderPane GridPane.rowIndex="0" GridPane.columnIndex="2" style="-fx-border-color: rgb(0,0,0); -fx-border-width:0px 0px 0.5px 0px">
            <Label text="Text">
                <font>
                <Font name="Arial" size="13"></Font>
                </font>
            </Label>
            </BorderPane>

            <BorderPane GridPane.rowIndex="0" GridPane.columnIndex="3" style="-fx-border-color: rgb(0,0,0); -fx-border-width:0px 0px 0.5px 0px">
            <Label text="Text">
                <font>
                <Font name="Arial" size="13"></Font>
                </font>
            </Label>
            </BorderPane>

            <BorderPane GridPane.rowIndex="0" GridPane.columnIndex="4" style="-fx-border-color: rgb(0,0,0); -fx-border-width:0px 0px 0.5px 0px">
            <Label text="Text">
                <font>
                <Font name="Arial" size="13"></Font>
                </font>
            </Label>
            </BorderPane>

            <Label text="Text" GridPane.rowIndex="1" GridPane.columnIndex="0">
                <font>
                <Font name="Arial" size="13"></Font>
                </font>
            </Label>
            <Label text="Text" GridPane.rowIndex="1" GridPane.columnIndex="1">
                <font>
                <Font name="Arial" size="13"></Font>
                </font>
            </Label>
            <Label text="Text" GridPane.rowIndex="1" GridPane.columnIndex="2">
                <font>
                <Font name="Arial" size="13"></Font>
                </font>
            </Label>
            <Label text="Text" GridPane.rowIndex="1" GridPane.columnIndex="3">
                <font>
                <Font name="Arial" size="13"></Font>
                </font>
            </Label>

        </GridPane>
<!-- ................................................................................... -->
    </TitledPane>
</VBox>
</BorderPane>

exampleController.java

package examplePackage;

public class exampleController
{

}

Main.java

package examplePackage;

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

public class Main extends Application
{
    @Override
    public void start(Stage primaryStage)
    {
        try {
            Parent root = FXMLLoader.load(getClass().getResource("example.fxml"));
            primaryStage.setScene(new Scene(root, 1920,800));
            primaryStage.setTitle("exampleTitle");
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args)
    {
        launch(args);
    }
}

问题是我将标签直接放在边框窗格内,没有使用“”标签来指定它们的对齐方式。

错误:

<BorderPane GridPane.rowIndex="0" GridPane.columnIndex="1">
    <Label text="Text">
        <font>
            <Font name="Arial" size="13"></Font>
        </font>
    </Label>
</BorderPane>

右:

<BorderPane GridPane.rowIndex="0" GridPane.columnIndex="1">
    <left>
        <Label text="Text">
            <font>
                <Font name="Arial" size="13"></Font>
            </font>
        </Label>
    </left>
</BorderPane>
```