我正在尝试在javafx中创建自定义工具栏.此工具栏应该能够在其表面的中心,左侧和右侧(三个部分)显示控件.问题是我不知道这个.我读了很多与这个问题相关的提示,但是他们不适合我,或者我做错了什么......
无论如何,我写了几个方法,它们代表了实现我的工具栏的不同方法,但没有一个正常工作.在这里你有我的尝试:
使用HBox Hgrow属性作为弹簧.没工作.
public ToolBar createToolBar()
{
ToolBar toolBar = new ToolBar();
Pane emptyPane = new Pane();
HBox spring = new HBox(emptyPane);
spring.setHgrow(emptyPane, Priority.ALWAYS);
toolBar.getItems().addAll(spring, new Label("LABEL"));
return toolBar;
}
Run Code Online (Sandbox Code Playgroud)2.它适用于左右两部分,但如何定义中心部分?
public AnchorPane createToolBar2()
{
AnchorPane toolBar = new AnchorPane();
Label leftLabel = new Label("left");
Label rightLabel = new Label("right");
toolBar.getChildren().addAll(leftLabel, rightLabel);
toolBar.setLeftAnchor(leftLabel, 0.0);
toolBar.setRightAnchor(rightLabel, 0.0);
return toolBar;
}
Run Code Online (Sandbox Code Playgroud)
这种方法适用于布局,但我无法监听左侧和中间部分的事件,因为这些事件由右侧部分覆盖(StackPane是原因),因此该解决方案也没用.
public StackPane createToolBar3()
{
StackPane toolBar = new StackPane();
Button left = new Button("left button");
Button right = new …Run Code Online (Sandbox Code Playgroud)