1+ import javafx .application .Application ;
2+ import javafx .collections .FXCollections ;
3+ import javafx .collections .ObservableList ;
4+ import javafx .geometry .Insets ;
5+ import javafx .scene .Scene ;
6+ import javafx .scene .control .Button ;
7+ import javafx .scene .control .TableColumn ;
8+ import javafx .scene .control .TableView ;
9+ import javafx .scene .control .TextField ;
10+ import javafx .scene .control .cell .PropertyValueFactory ;
11+ import javafx .scene .layout .HBox ;
12+ import javafx .scene .layout .VBox ;
13+ import javafx .stage .Stage ;
14+
15+ public class Main extends Application {
16+
17+ Stage window ;
18+ TableView <Product > table ;
19+
20+ public static void main (String [] args ) {
21+ launch (args );
22+ }
23+
24+ @ Override
25+ public void start (Stage primaryStage ) throws Exception {
26+ window = primaryStage ;
27+ window .setTitle ("thenewboston - JavaFX" );
28+
29+ //Name column
30+ TableColumn <Product , String > nameColumn = new TableColumn <>("Name" );
31+ nameColumn .setMinWidth (200 );
32+ nameColumn .setCellValueFactory (new PropertyValueFactory <>("name" ));
33+
34+ //Price column
35+ TableColumn <Product , Double > priceColumn = new TableColumn <>("Price" );
36+ priceColumn .setMinWidth (100 );
37+ priceColumn .setCellValueFactory (new PropertyValueFactory <>("price" ));
38+
39+ //Quantity column
40+ TableColumn <Product , String > quantityColumn = new TableColumn <>("Quantity" );
41+ quantityColumn .setMinWidth (100 );
42+ quantityColumn .setCellValueFactory (new PropertyValueFactory <>("quantity" ));
43+
44+ table = new TableView <>();
45+ table .setItems (getProduct ());
46+ table .getColumns ().addAll (nameColumn , priceColumn , quantityColumn );
47+
48+ VBox vBox = new VBox ();
49+ vBox .getChildren ().addAll (table );
50+
51+ Scene scene = new Scene (vBox );
52+ window .setScene (scene );
53+ window .show ();
54+ }
55+
56+ //Get all of the products
57+ public ObservableList <Product > getProduct (){
58+ ObservableList <Product > products = FXCollections .observableArrayList ();
59+ products .add (new Product ("Laptop" , 859.00 , 20 ));
60+ products .add (new Product ("Bouncy Ball" , 2.49 , 198 ));
61+ products .add (new Product ("Toilet" , 99.00 , 74 ));
62+ products .add (new Product ("The Notebook DVD" , 19.99 , 12 ));
63+ products .add (new Product ("Corn" , 1.49 , 856 ));
64+ return products ;
65+ }
66+
67+
68+ }
0 commit comments