Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.57 KB | None | 0 0
  1. package Core;
  2.  
  3. import javafx.application.Application;
  4. import javafx.beans.property.SimpleStringProperty;
  5. import javafx.collections.FXCollections;
  6. import javafx.collections.ObservableList;
  7. import javafx.scene.Group;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.Label;
  10. import javafx.scene.control.TableColumn;
  11. import javafx.scene.control.TableView;
  12. import javafx.scene.control.cell.PropertyValueFactory;
  13. import javafx.scene.layout.VBox;
  14. import javafx.scene.text.Font;
  15. import javafx.stage.Stage;
  16.  
  17. import java.awt.*;
  18.  
  19. public class Main2TestEnvironment extends Application {
  20.  
  21.     private final TableView<Person> table = new TableView<>();
  22.     private final ObservableList<Person> data =
  23.             FXCollections.observableArrayList(
  24.                     new Person("Jacob", "Smith", "jacob.smith@example.com"),
  25.                     new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
  26.                     new Person("Ethan", "Williams", "ethan.williams@example.com"),
  27.                     new Person("Emma", "Jones", "emma.jones@example.com"),
  28.                     new Person("Michael", "Brown", "michael.brown@example.com")
  29.             );
  30.  
  31.     public static void Main2TestEnvironment(String[] args) {
  32.         launch(args);
  33.     }
  34.  
  35.     @Override
  36.     public void start(Stage stage) {
  37.         Scene scene = new Scene(new Group());
  38.         stage.setTitle("Table View Sample");
  39.         stage.setWidth(450);
  40.         stage.setHeight(500);
  41.  
  42.         final Label label = new Label("Address Book");
  43.         label.setFont(new Font("Arial", 20));
  44.  
  45.         table.setEditable(true);
  46.  
  47.         TableColumn firstNameCol = new TableColumn("First Name");
  48.         firstNameCol.setMinWidth(100);
  49.         firstNameCol.setCellValueFactory(
  50.                 new PropertyValueFactory<>("firstName"));
  51.  
  52.         TableColumn lastNameCol = new TableColumn("Last Name");
  53.         lastNameCol.setMinWidth(100);
  54.         lastNameCol.setCellValueFactory(
  55.                 new PropertyValueFactory<>("lastName"));
  56.  
  57.         TableColumn emailCol = new TableColumn("Email");
  58.         emailCol.setMinWidth(200);
  59.         emailCol.setCellValueFactory(
  60.                 new PropertyValueFactory<>("email"));
  61.  
  62.         table.setItems(data);
  63.         table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
  64.  
  65.         final VBox vbox = new VBox();
  66.         vbox.setSpacing(5);
  67.         //vbox.setPadding(new Insets(10, 0, 0, 10));
  68.         vbox.getChildren().addAll(label, table);
  69.  
  70.         ((Group) scene.getRoot()).getChildren().addAll(vbox);
  71.  
  72.         stage.setScene(scene);
  73.         stage.show();
  74.     }
  75.  
  76.     public static class Person {
  77.  
  78.         private final SimpleStringProperty firstName;
  79.         private final SimpleStringProperty lastName;
  80.         private final SimpleStringProperty email;
  81.  
  82.         private Person(String fName, String lName, String email) {
  83.             this.firstName = new SimpleStringProperty(fName);
  84.             this.lastName = new SimpleStringProperty(lName);
  85.             this.email = new SimpleStringProperty(email);
  86.         }
  87.  
  88.         public String getFirstName() {
  89.             return firstName.get();
  90.         }
  91.  
  92.         public void setFirstName(String fName) {
  93.             firstName.set(fName);
  94.         }
  95.  
  96.         public String getLastName() {
  97.             return lastName.get();
  98.         }
  99.  
  100.         public void setLastName(String fName) {
  101.             lastName.set(fName);
  102.         }
  103.  
  104.         public String getEmail() {
  105.             return email.get();
  106.         }
  107.  
  108.         public void setEmail(String fName) {
  109.             email.set(fName);
  110.         }
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement