Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX-更改子项后,边框窗格/堆栈窗格未调整大小_Java_Resize_Javafx_Javafx 2 - Fatal编程技术网

JavaFX-更改子项后,边框窗格/堆栈窗格未调整大小

JavaFX-更改子项后,边框窗格/堆栈窗格未调整大小,java,resize,javafx,javafx-2,Java,Resize,Javafx,Javafx 2,在JavaFX边框窗格中添加和删除内容时,我遇到了调整大小的问题。手动调整窗口大小之前,不会调整边框窗格内容的大小。我已经编写了一个小型测试应用程序来模拟这种行为。应用程序构建一个BorderPane,其中包含一个嵌入在BorderPane中心的StackPane中的矩形。在BorderPane的底部有一个包含文本和分隔符的VBox和HBox。有一个菜单项可从BorderPane底部删除内容(MoveText->Right),并将类似内容添加到BorderPane的右侧位置 将文本添加到Bord

在JavaFX边框窗格中添加和删除内容时,我遇到了调整大小的问题。手动调整窗口大小之前,不会调整边框窗格内容的大小。我已经编写了一个小型测试应用程序来模拟这种行为。应用程序构建一个BorderPane,其中包含一个嵌入在BorderPane中心的StackPane中的矩形。在BorderPane的底部有一个包含文本和分隔符的VBox和HBox。有一个菜单项可从BorderPane底部删除内容(MoveText->Right),并将类似内容添加到BorderPane的右侧位置

将文本添加到BorderPane的右侧位置时,矩形与文本重叠。换句话说,边框窗格中心的内容与边框窗格右侧的内容重叠

我看到了以下链接- 调用requestLayout似乎没有帮助。我还尝试在图中的各个节点上调用impl_updatePG和impl_transformsChanged。我从这条线索中得到了这个想法-

公共类边框示例扩展应用程序
{
私有边界根;
专用StackPane中心窗格;
@凌驾
public void start(Stage primaryStage)引发异常
{
root=新边框窗格();
setTop(getMenu());
setBottom(getBottomVBox());
centerPane=getCenterPane();
root.setCenter(中心窗格);
场景=新场景(根,900500);
setTitle(“边框窗格示例”);
初级阶段。场景(场景);
primaryStage.show();
}
私有菜单栏getMenu()
{
菜单栏菜单栏=新建菜单栏();
MenuItem rightMenuItem=新MenuItem(“右”);
setOnAction(新的EventHandler()){
@凌驾
公共无效句柄(ActionEvent ActionEvent){
setRight(getRightHBox());
root.setBottom(null);
root.requestLayout();
}
});
MenuItem bottomMenuItem=新MenuItem(“底部”);
setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(ActionEvent ActionEvent){
root.setRight(null);
setBottom(getBottomVBox());
}
});
菜单菜单=新菜单(“移动文本”);
menu.getItems().add(rightMenuItem);
menu.getItems().add(bottomMenuItem);
menuBar.getMenus().addAll(菜单);
返回菜单栏;
}
私有HBox getRightHBox()
{
HBox HBox=新的HBox();
VBox VBox=新的VBox(50);
设置填充(新的插入(0,20,0,20));
vbox.setAlignment(位置中心);
vbox.getChildren().addAll(新文本(“附加信息1”),
新文本(“附加信息2”)、新文本(“附加信息3”);
hbox.getChildren().addAll(新分隔符(方向.垂直),vbox);
返回hbox;
}
私有VBox getBottomVBox()
{
VBox VBox=新的VBox();
HBox HBox=新的HBox(20);
hbox.设置填充(新插图(5));
hbox.设置校准(位置中心);
hbox.getChildren().addAll(新文本(“页脚项目1”)
,新文本(“页脚项目2”)、新文本(“页脚项目3”);
vbox.getChildren().addAll(新分隔符(),hbox);
返回vbox;
}
私有StackPane getCenterPane()
{
StackPane StackPane=新的StackPane();
堆叠窗格。设置对齐(位置中心);
最终矩形rec=新矩形(200200);
rec.setFill(颜色减淡蓝色);
rec.widthProperty().bind(stackPane.widthProperty().subtract(50));
rec.heightProperty().bind(stackPane.heightProperty().subtract(50));
stackPane.getChildren().addAll(rec);
返回堆栈窗格;
}
公共静态void main(字符串[]args)
{
应用程序启动(args);
}
}
如有任何建议,将不胜感激。
为了得到答案,谢谢你:

StackPane
需要设置其最小大小才能进行剪裁。因此,如果显式添加
stackPane.setMinSize(0,0)
getCenterPane()
方法,它应该可以解决您的问题

因此,您的
getCenterPane()
方法现在看起来如下所示:

private StackPane getCenterPane()
{
  StackPane stackPane = new StackPane();
  stackPane.setMinSize(0, 0);
  stackPane.setAlignment(Pos.CENTER);

  final Rectangle rec = new Rectangle(200, 200);
  rec.setFill(Color.DODGERBLUE);
  rec.widthProperty().bind(stackPane.widthProperty().subtract(50));
  rec.heightProperty().bind(stackPane.heightProperty().subtract(50));

  stackPane.getChildren().addAll(rec);

  return stackPane;
}

看起来我在-。>在边框窗格中显式设置中心窗格的最小宽度设置,使其不会溢出外部边缘窗格。将stackPane.setMinSize(0,0)添加到getCenterPane()可以解决此问题。。
private StackPane getCenterPane()
{
  StackPane stackPane = new StackPane();
  stackPane.setMinSize(0, 0);
  stackPane.setAlignment(Pos.CENTER);

  final Rectangle rec = new Rectangle(200, 200);
  rec.setFill(Color.DODGERBLUE);
  rec.widthProperty().bind(stackPane.widthProperty().subtract(50));
  rec.heightProperty().bind(stackPane.heightProperty().subtract(50));

  stackPane.getChildren().addAll(rec);

  return stackPane;
}