Group javafx

@DefaultProperty(value="children")
public class Group

extends Parent


A Group node contains an ObservableList of children that are rendered in order whenever this node is rendered.
A Group will take on( 承担) the collective( 集体的) bounds of its children and is not directly resizable.


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.


By default, a Group will "auto-size" its managed resizable children to their preferred sizes during the layout pass to ensure that Regions and Controls are sized properly as their state changes. If an application needs to disable this auto-sizing behavior, then it should set autoSizeChildren to false and understand that if the preferred size of the children change, they will not automatically resize (so buyer beware!).


Group Example:


import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import java.lang.Math;


Group g = new Group();
for (int i = 0; i < 5; i++) {
    Rectangle r = new Rectangle();
    r.setY(i * 20);
    r.setWidth(100);
    r.setHeight(10);
    r.setFill(Color.RED);
    g.getChildren().add(r);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JavaFX中,Group是一个容器节点,它允许您将多个节点组合成一个单一的可视化元素。您可以将其他节点添加到Group中,然后将Group添加到场景图中。 Group不具有宽度和高度属性,它的大小取决于其子节点的大小和位置。当您将节点添加到Group中时,它们的坐标是相对于Group的(0,0)点。 以下是一个简单的示例,演示如何使用Group: ``` import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception { // 创建三个圆形节点 Circle circle1 = new Circle(50, 50, 25, Color.RED); Circle circle2 = new Circle(100, 100, 25, Color.GREEN); Circle circle3 = new Circle(150, 150, 25, Color.BLUE); // 创建一个Group,并将三个圆形节点添加到其中 Group group = new Group(); group.getChildren().addAll(circle1, circle2, circle3); // 创建一个Scene,并将Group添加到其中 Scene scene = new Scene(group, 300, 300); // 将Scene设置为primaryStage的场景,并显示primaryStage primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } ``` 在这个例子中,我们创建了三个圆形节点,并将它们添加到一个Group中。然后我们创建一个Scene,并将Group添加到其中。最后,我们将Scene设置为primaryStage的场景,并显示primaryStage。 运行这个程序,您将看到三个圆形节点在窗口中居中显示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值