Layout JAVAFX-将节点添加到标题窗格';s头

Layout JAVAFX-将节点添加到标题窗格';s头,layout,javafx,alignment,nodes,Layout,Javafx,Alignment,Nodes,我想将节点添加到标题窗格的标题中。我找到的唯一方法是使用setGraphic()方法 使用这种方式的问题是我无法将它们整齐地放置。以下是我得到的: 代码 TitledPane tpane = new TitledPane(); tpane.setContent(new Text("Content")); tpane.setExpanded(false); Button b = new Button("Delete");

我想将节点添加到
标题窗格
的标题中。我找到的唯一方法是使用
setGraphic()
方法

使用这种方式的问题是我无法将它们整齐地放置。以下是我得到的:

代码

        TitledPane tpane = new TitledPane();
        tpane.setContent(new Text("Content"));
        tpane.setExpanded(false);

        Button b = new Button("Delete");            

        BorderPane box = new BorderPane();
        box.setLeft(new Text("1 "));
        box.setCenter(new Text("Single Pane"));            
        box.setRight(b);     


        AnchorPane par = new AnchorPane(box);
        tpane.setGraphic(par);

        VBox vbox = new VBox();
        vbox.getChildren().add(tpane); 
目标

我想把
Delete
按钮放在右边,这就是我使用
Borderpane
的原因。因此,
边框窗格
需要填充整个
标题窗格
的标题宽度减去小三角形的空间


如何在
setGraphic()方法中完成?或者有更好的方法来实现它吗?

要解决您的问题,请尝试将边界窗格的宽度设置为场景的宽度减去箭头,如下所示

TitledPane tpane = new TitledPane();
    tpane.setContent(new Text("Content"));
    tpane.setExpanded(false);

    Button b = new Button("Delete");            

    BorderPane box = new BorderPane();
    box.setLeft(new Text("1 "));
    box.setCenter(new Text("Single Pane"));            
    box.setRight(b);     


    AnchorPane par = new AnchorPane(box);
    tpane.setGraphic(par);

    VBox vbox = new VBox();
    vbox.getChildren().add(tpane); 

    box.setPrefWidth(scene.getWidth()-30);//You can adjust the number to fit your needs and change scene to whatever the name of your scene is 

我希望这有助于解决您的问题,请尝试将BorderPane的宽度设置为场景的宽度减去箭头,如下所示

TitledPane tpane = new TitledPane();
    tpane.setContent(new Text("Content"));
    tpane.setExpanded(false);

    Button b = new Button("Delete");            

    BorderPane box = new BorderPane();
    box.setLeft(new Text("1 "));
    box.setCenter(new Text("Single Pane"));            
    box.setRight(b);     


    AnchorPane par = new AnchorPane(box);
    tpane.setGraphic(par);

    VBox vbox = new VBox();
    vbox.getChildren().add(tpane); 

    box.setPrefWidth(scene.getWidth()-30);//You can adjust the number to fit your needs and change scene to whatever the name of your scene is 

我希望这有助于

嗯,对javafx用户的支持似乎没有主流框架那么大

在@Austin的建议下,我尝试了几次,找到了我想要的方法,这也是give dynamic size

box.prefWidthProperty().bind(scene.widthProperty().subtract(35))


对javafx用户的支持似乎没有主流框架那么大

在@Austin的建议下,我尝试了几次,找到了我想要的方法,这也是give dynamic size

box.prefWidthProperty().bind(scene.widthProperty().subtract(35))


我想您尝试过它,但没有将边框窗格包装到锚窗格中。相同的结果?@James_D我做了,没有发生任何变化。我想你没有在锚定窗格中包装边框窗格就尝试了。同样的结果?@James_D我做到了,没有什么不同。