import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
public class Main extends Application {
public void start(Stage stage) {
// يمثل الجدول الذي نريد إضافته في النافذة TableView هنا قمنا بإنشاء كائن من الكلاس
TableView table = new TableView();
// يمثل مجموعة البيانات التي ستظهر في الجدول Observableهنا قمنا بإنشاء كائن من الكلاس
// Product كل سطر في هذا الجدول يمثل كائن من الكلاس
ObservableList<Product> data = FXCollections.observableArrayList(
new Product("Laptop", 800.00, 3),
new Product("Camera", 199.99, 12),
new Product("Hard Disk", 79.99, 8),
new Product("Projector", 240.55, 7),
new Product("PC Screen", 120.00, 6),
new Product("Speakers", 33.00, 10),
new Product("Headphones", 12.50, 4),
new Product("Microphone", 24.75, 5)
// table تمثل الأعمدة التي سنضيفها في الكائن TableColumn هنا قمنا بإنشاء ثلاث كائنات
TableColumn columnName = new TableColumn("Name");
TableColumn columnPrice = new TableColumn("Price ($)");
TableColumn columnQuantity = new TableColumn("Quantity");
// table هنا وضعنا الأعمدة الثلاثة في الكائن
table.getColumns().addAll(columnName, columnPrice, columnQuantity);
// table في الكائن data هنا قمنا بوضع بيانات الكائن
// تم إضافته في الجدول Product الموجودة في كل كائن name سيُعرض فيه قيم الـ columnName هنا قلنا أن العامود
columnName.setCellValueFactory( new PropertyValueFactory<>("name") );
// تم إضافته في الجدول Product الموجودة في كل كائن price سيُعرض فيه قيم الـ columnPrice هنا قلنا أن العامود
columnPrice.setCellValueFactory( new PropertyValueFactory<>("price") );
// تم إضافته في الجدول Product الموجودة في كل كائن quantity سيُعرض فيه قيم الـ columnQuantity هنا قلنا أن العامود
columnQuantity.setCellValueFactory( new PropertyValueFactory<>("quantity") );
// في النافذة table هنا قمنا بتحديد حجم الكائن
table.setPrefSize(440, 300);
// حتى نستغل كل الحجم الذي حجزناه له table هنا قمنا بتحديد عرض كل عامود بداخل الكائن
columnName.setPrefWidth(144);
columnPrice.setPrefWidth(144);
columnQuantity.setPrefWidth(150);
// في النافذة table هنا قمنا بتحديد مكان ظهور الكائن
// في النافذة Root Node لأننا ننوي جعله الـ Group هنا قمنا بإنشاء كائن من الكلاس
Group root = new Group();
// root في الكائن table هنا قمنا بإضافة الكائن
root.getChildren().add(table);
// فيها و تحديد حجمها Node كأول root هنا قمنا بإنشاء محتوى النافذة مع تعيين الكائن
Scene scene = new Scene(root, 460, 320);
// هنا وضعنا عنوان للنافذة
stage.setTitle("JavaFX TableView");
// أي وضعنا محتوى النافذة الذي قمنا بإنشائه للنافذة .stage في كائن الـ scene هنا وضعنا كائن الـ
// هنا قمنا بإظهار النافذة
// هنا قمنا بتشغيل التطبيق
public static void main(String[] args) {
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage stage) {
// يمثل الجدول الذي نريد إضافته في النافذة TableView هنا قمنا بإنشاء كائن من الكلاس
TableView table = new TableView();
// يمثل مجموعة البيانات التي ستظهر في الجدول Observableهنا قمنا بإنشاء كائن من الكلاس
// Product كل سطر في هذا الجدول يمثل كائن من الكلاس
ObservableList<Product> data = FXCollections.observableArrayList(
new Product("Laptop", 800.00, 3),
new Product("Camera", 199.99, 12),
new Product("Hard Disk", 79.99, 8),
new Product("Projector", 240.55, 7),
new Product("PC Screen", 120.00, 6),
new Product("Speakers", 33.00, 10),
new Product("Headphones", 12.50, 4),
new Product("Microphone", 24.75, 5)
);
// table تمثل الأعمدة التي سنضيفها في الكائن TableColumn هنا قمنا بإنشاء ثلاث كائنات
TableColumn columnName = new TableColumn("Name");
TableColumn columnPrice = new TableColumn("Price ($)");
TableColumn columnQuantity = new TableColumn("Quantity");
// table هنا وضعنا الأعمدة الثلاثة في الكائن
table.getColumns().addAll(columnName, columnPrice, columnQuantity);
// table في الكائن data هنا قمنا بوضع بيانات الكائن
table.setItems(data);
// تم إضافته في الجدول Product الموجودة في كل كائن name سيُعرض فيه قيم الـ columnName هنا قلنا أن العامود
columnName.setCellValueFactory( new PropertyValueFactory<>("name") );
// تم إضافته في الجدول Product الموجودة في كل كائن price سيُعرض فيه قيم الـ columnPrice هنا قلنا أن العامود
columnPrice.setCellValueFactory( new PropertyValueFactory<>("price") );
// تم إضافته في الجدول Product الموجودة في كل كائن quantity سيُعرض فيه قيم الـ columnQuantity هنا قلنا أن العامود
columnQuantity.setCellValueFactory( new PropertyValueFactory<>("quantity") );
// في النافذة table هنا قمنا بتحديد حجم الكائن
table.setPrefSize(440, 300);
// حتى نستغل كل الحجم الذي حجزناه له table هنا قمنا بتحديد عرض كل عامود بداخل الكائن
columnName.setPrefWidth(144);
columnPrice.setPrefWidth(144);
columnQuantity.setPrefWidth(150);
// في النافذة table هنا قمنا بتحديد مكان ظهور الكائن
table.setTranslateX(10);
table.setTranslateY(10);
// في النافذة Root Node لأننا ننوي جعله الـ Group هنا قمنا بإنشاء كائن من الكلاس
Group root = new Group();
// root في الكائن table هنا قمنا بإضافة الكائن
root.getChildren().add(table);
// فيها و تحديد حجمها Node كأول root هنا قمنا بإنشاء محتوى النافذة مع تعيين الكائن
Scene scene = new Scene(root, 460, 320);
// هنا وضعنا عنوان للنافذة
stage.setTitle("JavaFX TableView");
// أي وضعنا محتوى النافذة الذي قمنا بإنشائه للنافذة .stage في كائن الـ scene هنا وضعنا كائن الـ
stage.setScene(scene);
// هنا قمنا بإظهار النافذة
stage.show();
}
// هنا قمنا بتشغيل التطبيق
public static void main(String[] args) {
launch(args);
}
}