javafx组容器Group

Group

Group不同于其他一般布局,Group直接继承于Parent。使用无法读取
文档中对Group的说明:
A Group node contains an ObservableList of children that are rendered in order whenever this node is rendered.
Group容器的子节点放在一个可观察列表中,显示时按顺序呈现。
A Group will take on the collective bounds of its children and is not directly resizable.
一个Group容器的大小由子节点决定,并且不能直接调整大小。
Any transform, effect, or state applied to a Group will be applied to all children of that group. Such transforms and effects will NOT be included in this Group’s layout bounds, however if transforms and effects are set directly on children of this Group, those will be included in this Group’s layout bounds.
对Group容器的任何变换,特效和渲染都将应用于它的所有子节点。此类转换和效果将不包含在该布局边界,但是,如果直接对该组的子元素设置转换和效果,则这些转换和效果将包含在该组的布局边界中。

关于Group高度和宽度属性

由于Group直接继承于Parent。所以访问高度和宽度属性。

文档中对高度的说明:
Group defines the preferred height as simply being the height of its layout bounds, which in turn is simply the union of the layout bounds of all of its children. That is, the preferred height is the one that it is at, because a Group cannot be resized. Note: as the layout bounds in autosize Group depend on the Group to be already laid-out, this call will do the layout of the Group if necessary.

可以理解为Group容器的大小由子节点决定,即它的大小为容纳所有子节点的矩形大小。

	public static void main(String[] args) {
		launch();
	}
	public void start(Stage primaryStage) throws Exception {
		Group g=new Group();
		Button b=new Button ("button");
		g.getChildren().add(b);
		System.out.println(g);
		Scene s=new Scene(g);
		primaryStage.setScene(s);
		primaryStage.show();
	}
}

在这里插入图片描述

子节点位置变换将改变Group大小
		b.setLayoutX(100);
		b.setLayoutY(100);

在这里插入图片描述

子节点为位置设置

位置没有指明时默认为(0,0),多个节点将重合,后添加的显示在上面

		Group g=new Group();
		g.setAutoSizeChildren(true);
		Button b=new Button ("button");
		b.setFont(new Font(40));
		g.getChildren().add(b);
		g.getChildren().add(new Button ("button2"));

在这里插入图片描述

检查某位置是否有子节点

一个节点的位置由它的左上角确定

	System.out.println(g.contains(10,10));
	System.out.println(g.contains(0,0));

false
true
虽然(10,10)在Button里面但仍为false

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值