项目总结控件

一.文本输入类控件

文本输入类控件用于接收用户的输入。

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) {
        TextField textField = new TextField();

        StackPane root = new StackPane();
        root.getChildren().add(textField);

        Scene scene = new Scene(root, 300, 200);

        primaryStage.setTitle("JavaFX应用程序");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

二.列表类控件

列表类控件用于展示列表数据。

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) {
        TableView<User> tableView = new TableView<>();
        TableColumn<User, String> nameCol = new TableColumn<>("姓名");
        TableColumn<User, Integer> ageCol = new TableColumn<>("年龄");

        nameCol.setCellValueFactory(new PropertyValueFactory<>("name"));
        ageCol.setCellValueFactory(new PropertyValueFactory<>("age"));

        tableView.getColumns().addAll(nameCol, ageCol);
        tableView.getItems().addAll(
                new User("张三", 20),
                new User("李四", 25),
                new User("王五", 30)
        );

        StackPane root = new StackPane();
        root.getChildren().add(tableView);

        Scene scene = new Scene(root, 300, 200);

        primaryStage.setTitle("JavaFX应用程序");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

三.布局类控件

布局类控件用于管理其他控件的位置和大小。

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) {
        Label label1 = new Label("Label 1");
        Label label2 = new Label("Label 2");

        VBox box = new VBox();
        box.getChildren().addAll(label1, label2);

        StackPane root = new StackPane();
        root.getChildren().add(box);

        Scene scene = new Scene(root, 300, 200);

        primaryStage.setTitle("JavaFX应用程序");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值