10.JavaFx AnchorPane

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

/**
 * AnchorPane
 */
public class Demo11 extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Button button1 = new Button("按钮1");
        Button button2 = new Button("按钮2");

        // 布局
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: RED");
        anchorPane.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                System.out.println("pane single click");
            }
        });
//        AnchorPane.setLeftAnchor(button1, 10.0);
//        AnchorPane.setTopAnchor(button1, 10.0);
//
//        AnchorPane.setLeftAnchor(button2, 60.0);
//        AnchorPane.setTopAnchor(button2, 10.0);
//        anchorPane.getChildren().addAll(button1, button2);

        Button groupButton1 = new Button("group按钮1");
        Button groupButton2 = new Button("group按钮2");
        Button groupButton3 = new Button("group按钮3");
        Button groupButton4 = new Button("group按钮4");

        Group group1 = new Group();
        Group group2 = new Group();
        group1.getChildren().addAll(groupButton1, groupButton2);
        group2.getChildren().addAll(groupButton3, groupButton4);

        anchorPane.getChildren().addAll(group1, group2);
        AnchorPane.setLeftAnchor(group1, 10.0);
        AnchorPane.setTopAnchor(group1, 10.0);

        AnchorPane.setLeftAnchor(group2, 500.0);
        AnchorPane.setTopAnchor(group2, 10.0);

        groupButton1.setLayoutX(0);
        groupButton1.setLayoutY(100);

        groupButton2.setLayoutX(0);
        groupButton2.setLayoutY(200);

        groupButton3.setLayoutX(0);
        groupButton3.setLayoutY(300);

        groupButton4.setLayoutX(0);
        groupButton4.setLayoutY(400);


        Scene scene = new Scene(anchorPane);
        stage.setScene(scene);
        stage.setTitle("javafx");
        stage.setWidth(800);
        stage.setHeight(800);
        stage.show();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值