- 容纳一组按钮的容器
- 支持水平、垂直布局
- 内容太多,会自动折叠
常用属性
orientation
排列方式,Orientation.VERTICAL、Orientation.HORIZONTAL
flowPane.setOrientation(Orientation.HORIZONTAL);
padding
内边距,可以单独设置上、下、左、右的内边距
flowPane.setPadding(new Insets(10, 10, 10, 10));
实现方式
Java实现
public static ToolBar demo1() {
ToolBar toolBar = new ToolBar();
// 布局方向
toolBar.setOrientation(Orientation.VERTICAL);
// 内边距
toolBar.setPadding(new Insets(10, 10, 10, 10));
for (int i = 1; i <= 10; i++) {
Button btn = new Button("Button " + i);
Separator separator = new Separator();
toolBar.getItems().addAll(btn, separator);
}
return toolBar;
}
fxml实现
<StackPane alignment="TOP_LEFT" prefHeight="400" prefWidth="600" xmlns="http://javafx.com/javafx/17.0.2-ea"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<ToolBar prefHeight="40.0" prefWidth="200.0">
<items>
<Button mnemonicParsing="false" text="Button 1"/>
<Separator/>
<Button mnemonicParsing="false" text="Button 2"/>
<Separator/>
<Button mnemonicParsing="false" text="Button 3"/>
<Separator/>
<Button mnemonicParsing="false" text="Button 4"/>
<Separator/>
<Button mnemonicParsing="false" text="Button 5"/>
<Separator/>
<Button mnemonicParsing="false" text="Button 6"/>
<Separator/>
<Button mnemonicParsing="false" text="Button 7"/>
<Separator/>
<Button mnemonicParsing="false" text="Button 8"/>
<Separator/>
<Button mnemonicParsing="false" text="Button 9"/>
<Separator/>
<Button mnemonicParsing="false" text="Button 10"/>
<Separator/>
</items>
</ToolBar>
</children>
</StackPane>
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » JavaFX布局-ToolBar
发表评论 取消回复