Advertisement
apl-mhd

TableView

Nov 29th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 KB | None | 0 0
  1. package sample;
  2. import java.util.*;
  3. import javafx.application.Application;
  4. import javafx.collections.FXCollections;
  5. import javafx.collections.ObservableList;
  6. import javafx.fxml.FXMLLoader;
  7. import javafx.scene.Parent;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.TableColumn;
  10. import javafx.scene.control.TableView;
  11. import javafx.scene.control.cell.PropertyValueFactory;
  12. import javafx.scene.layout.StackPane;
  13. import javafx.scene.layout.VBox;
  14. import javafx.stage.Stage;
  15.  
  16. import javax.swing.text.TabableView;
  17. import java.util.Observable;
  18.  
  19. public class Main extends Application {
  20.     public static void main(String[] args) {
  21.         launch(args);
  22.     }
  23.  
  24.     Stage window;
  25.  
  26.     TableView<Products> table;
  27.  
  28.  
  29.     @Override
  30.     public void start(Stage primaryStage) throws Exception{
  31.  
  32.         window = primaryStage;
  33.  
  34.         window.setTitle("orko");
  35.  
  36.         //product name
  37.         TableColumn<Products, String> namecolumn = new TableColumn<>("Name");
  38.         namecolumn.setMinWidth(100);
  39.         namecolumn.setCellValueFactory(new PropertyValueFactory<>("Name"));
  40.  
  41.         //product Price
  42.         TableColumn<Products, String> priceColumn = new TableColumn<>("Price");
  43.         priceColumn.setMinWidth(100);
  44.         priceColumn.setCellValueFactory(new PropertyValueFactory<>("Price"));
  45.  
  46. //product Quantity
  47.         TableColumn<Products, String> quantityColumn = new TableColumn<>("Quantity");
  48.         quantityColumn.setMinWidth(100);
  49.         quantityColumn.setCellValueFactory(new PropertyValueFactory<>("Quantity"));
  50.  
  51.  
  52.         table = new TableView<>();
  53.         table.setItems(getProduct());
  54.         table.getColumns().addAll(namecolumn,priceColumn,quantityColumn);
  55.  
  56.         VBox layout = new VBox();
  57.         layout.getChildren().addAll(table);
  58.         Scene scene = new Scene(layout);
  59.  
  60.         primaryStage.setScene(scene);
  61.        primaryStage.show();
  62.     }
  63.  
  64.  
  65.     public ObservableList<Products> getProduct(){
  66.  
  67.         ObservableList<Products> products = FXCollections.observableArrayList();
  68.  
  69.         products.add(new Products("Laptop",10.0,1));
  70.  
  71.  
  72.         return  products;
  73.     }
  74.  
  75.  
  76.  
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. package sample;
  88.  
  89. public class Products {
  90.     String name;
  91.     double price;
  92.     int quantity;
  93.  
  94.     public Products(){
  95.  
  96.         name = "";
  97.         price=0;
  98.         quantity=0;
  99.     }
  100.  
  101.     public Products(String name, double price, int quantity) {
  102.         this.name = name;
  103.         this.price = price;
  104.         this.quantity = quantity;
  105.     }
  106.  
  107.     public String getName() {
  108.         return name;
  109.     }
  110.  
  111.     public void setName(String name) {
  112.         this.name = name;
  113.     }
  114.  
  115.     public double getPrice() {
  116.         return price;
  117.     }
  118.  
  119.     public void setPrice(double price) {
  120.         this.price = price;
  121.     }
  122.  
  123.     public int getQuantity() {
  124.         return quantity;
  125.     }
  126.  
  127.     public vaoid setQuantity(int quantity) {
  128.         this.quantity = quantity;
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement