Java 调整标题窗格中图形节点的大小';s头

Java 调整标题窗格中图形节点的大小';s头,java,layout,resize,javafx-2,Java,Layout,Resize,Javafx 2,我认为JavaFX的标题窗格在其标题中使用图形节点时显示了错误的大小调整行为。例如,当我将BorderPane实例作为图形(使用Label#setGraphic)添加到标签,并且将contentDisplay设置为graphic\u ONLY时,BorderPane实例始终占据标签的整个内部。 相反,当我对标题窗格执行相同操作时,BorderPane会忽略标题窗格标题的实际大小,但始终使用其首选的宽度和高度。 我希望Label和TitledPane显示相同的大小调整行为,因为它们都是标记的同一超

我认为JavaFX的标题窗格在其标题中使用图形节点时显示了错误的大小调整行为。例如,当我将
BorderPane
实例作为图形(使用
Label#setGraphic
)添加到标签,并且将
contentDisplay
设置为
graphic\u ONLY
时,
BorderPane
实例始终占据标签的整个内部。 相反,当我对标题窗格执行相同操作时,BorderPane会忽略标题窗格标题的实际大小,但始终使用其首选的宽度和高度。 我希望Label和TitledPane显示相同的大小调整行为,因为它们都是标记的同一超类的子类。(当然,
TitledPane
还需要处理额外的箭头按钮。)

下面的小程序演示了标题窗格和标签的不同布局行为

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.control.LabelBuilder;
import javafx.scene.control.TitledPane;
import javafx.scene.control.TitledPaneBuilder;
import javafx.scene.layout.BorderPaneBuilder;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class LayoutProblem extends Application {

    @Override
    public void start(Stage primaryStage) {

        TitledPane tPane = TitledPaneBuilder.create().graphic(
                BorderPaneBuilder.create().prefHeight(20).prefWidth(100)
                .style("-fx-border-color: black;").build()
            ).contentDisplay(ContentDisplay.GRAPHIC_ONLY)
                .maxWidth(Double.MAX_VALUE).build();

        Label label = LabelBuilder.create().graphic(
                BorderPaneBuilder.create().prefHeight(20).prefWidth(100)
                .style("-fx-border-color: black;").build()
            ).contentDisplay(ContentDisplay.GRAPHIC_ONLY)
            .maxWidth(Double.MAX_VALUE).build();

        VBox vBox = new VBox(10);
        vBox.getChildren().addAll(tPane, label);
        vBox.setPrefWidth(300);
        primaryStage.setScene(new Scene(vBox));
        primaryStage.show();

    }

    public static void main(String[] args) { launch(args); }
} 
如何管理
BorderPane
实例以占用标题栏标题中的完整可用空间(最好考虑箭头按钮)


也许可以使用css查找并编写一些宽度属性绑定特技,但我认为应该有一个更方便的解决方案

你能用borderpane图形显示标题窗格的屏幕截图,直观地想象问题吗?尝试使用内置css选择器
.titled pane>.title
的插入和填充。我已尝试添加屏幕截图。不幸的是,我需要10个声誉张贴图片。但是,我添加了一些代码。