javafx2中控件的自动调整大小
我正在尝试在场景图中添加一个 ToolBar 控件,其中包含 2 个按钮和一个 TextField。 我希望 TextField 控件自动调整大小并获取工具栏中的所有可用空间。因此,我使用 HBox 布局控件来添加按钮和文本字段。 我做了如下:
ToolBar tb = new ToolBar();
HBox hbox = new HBox(8);
TextField tf = new TextField();
HBox.setHgrow(tf, Priority.ALWAYS);
hbox.getChildren().add(new Button("<-"));
hbox.getChildren().add(new Button("->"));
hbox.getChildren().add(tf);
tb.getItems().add(hbox);
但它不起作用。我哪里错了?请帮忙。
I am trying to add a ToolBar control, containing 2 Buttons and a TextField in my scene graph.
I want that the TextField control gets automatically resized and acquire all the space available into toolbar. So, I used the HBox layout control to add the buttons and textfield.
I did as followed:
ToolBar tb = new ToolBar();
HBox hbox = new HBox(8);
TextField tf = new TextField();
HBox.setHgrow(tf, Priority.ALWAYS);
hbox.getChildren().add(new Button("<-"));
hbox.getChildren().add(new Button("->"));
hbox.getChildren().add(tf);
tb.getItems().add(hbox);
But its not working. Where am I going wrong? Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试下一步:
You can try next: