Advertisement
Guest User

Untitled

a guest
Jun 5th, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. package view;
  2. import javafx.application.Application;
  3. import javafx.beans.property.SimpleStringProperty;
  4. import javafx.collections.FXCollections;
  5. import javafx.collections.ObservableList;
  6. import javafx.geometry.Insets;
  7. import javafx.geometry.Orientation;
  8. import javafx.scene.Group;
  9. import javafx.scene.Node;
  10. import javafx.scene.Scene;
  11. import javafx.scene.control.Label;
  12. import javafx.scene.control.ScrollBar;
  13. import javafx.scene.control.TableColumn;
  14. import javafx.scene.control.TableView;
  15. import javafx.scene.control.TextField;
  16. import javafx.scene.control.cell.PropertyValueFactory;
  17. import javafx.scene.layout.VBox;
  18. import javafx.scene.text.Font;
  19. import javafx.stage.Stage;
  20. public class UserListView extends Application {
  21.  
  22. private TableView<Person> table = new TableView<Person>();
  23. private int start = 0, s = 0;
  24. private int step = 1;
  25. private final ObservableList<Person> data = FXCollections.observableArrayList();
  26.  
  27. /* new Person("Jacob", "Smith", "jacob.smith@example.com"),
  28. new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
  29. new Person("Ethan", "Williams", "ethan.williams@example.com"),
  30. new Person("Emma", "Jones", "emma.jones@example.com"),
  31. new Person("Michael", "Brown", "michael.brown@example.com"),
  32. new Person("Michael", "Brown", "michael.brown@example.com")
  33.  
  34. );*/
  35.  
  36. public static void main(String[] args) {
  37. launch(args);
  38. }
  39. private void populateInitialList() {
  40. data.add(new Person("Jacob", "Smith", "jacob.smith@example.com"));
  41. data.add(new Person("Isabella", "Johnson", "isabella.johnson@example.com"));
  42. data.add(new Person("Ethan", "Williams", "ethan.williams@example.com"));
  43. data.add(new Person("Emma", "Jones", "emma.jones@example.com"));
  44. data.add(new Person("Michael", "Brown", "michael.brown@example.com"));
  45. data.add(new Person("Emma", "Jones", "emma.jones@example.com"));
  46. data.add(new Person("Emma", "Jones", "emma.jones@example.com"));
  47.  
  48. }
  49. @Override
  50. public void start(Stage stage) {
  51. stage.setTitle("Table View Sample");
  52. stage.setWidth(450);
  53. stage.setHeight(200);
  54.  
  55. final Label label = new Label("Address Book");
  56. label.setFont(new Font("Arial", 20));
  57.  
  58. TableColumn<Person, String> firstNameCol = new TableColumn<Person, String>("First Name");
  59. firstNameCol.setMinWidth(100);
  60. firstNameCol.setCellValueFactory(
  61. new PropertyValueFactory<Person, String>("firstName"));
  62.  
  63. TableColumn<Person, String> lastNameCol = new TableColumn<Person, String>("Last Name");
  64. lastNameCol.setMinWidth(100);
  65. lastNameCol.setCellValueFactory(
  66. new PropertyValueFactory<Person, String>("lastName"));
  67.  
  68. TableColumn<Person, String> emailCol = new TableColumn<Person, String>("Email");
  69. emailCol.setMinWidth(200);
  70. emailCol.setCellValueFactory(
  71. new PropertyValueFactory<Person, String>("email"));
  72. populateInitialList();
  73. table.setItems(data);
  74. table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
  75.  
  76.  
  77. Scene scene = new Scene(table);
  78.  
  79. stage.setScene(scene);
  80. stage.show();
  81. ScrollBar tableViewScrollBar = getTableViewScrollBar(table);
  82. tableViewScrollBar.valueProperty().addListener((observable, oldValue, newValue) -> {
  83. double position = newValue.doubleValue();
  84. ScrollBar scrollBar = getTableViewScrollBar(table);
  85. if (position == scrollBar.getMax()) {
  86. if (step <= 50) {
  87. data.add(new Person("Emma", "Jones", "emma.jones@example.com"));
  88. //listItems.addAll(r);
  89. //System.out.println("start " + start + " " + "step " + step);
  90. start = step;
  91. step += 1;
  92. /*
  93. * listItems.remove(0); listItems.remove(0);
  94. * listItems.remove(0); listItems.remove(0); s+=4;
  95. */
  96. scrollBar.decrement();
  97. }
  98. } else if (position == scrollBar.getMin()) {
  99. /*
  100. * if(s > 0){ step = start; start -= 4; s -= 4; listItems.add(0,
  101. * bigData.get(s)); listItems.add(1, bigData.get(s+1));
  102. * listItems.add(2, bigData.get(s+2)); listItems.add(3,
  103. * bigData.get(s+3)); listItems.remove(listItems.size()-1);
  104. * listItems.remove(listItems.size()-1);
  105. * listItems.remove(listItems.size()-1);
  106. * listItems.remove(listItems.size()-1); scrollBar.increment();
  107. * System.out.println("hiiii"); }
  108. */
  109. }
  110. });
  111. }
  112. private ScrollBar getTableViewScrollBar(TableView<?> tab) {
  113. ScrollBar scrollbar = null;
  114. for (Node node : tab.lookupAll(".scroll-bar")) {
  115. if (node instanceof ScrollBar) {
  116. ScrollBar bar = (ScrollBar) node;
  117. if (bar.getOrientation().equals(Orientation.VERTICAL)) {
  118. scrollbar = bar;
  119. }
  120. }
  121. }
  122. return scrollbar;
  123. }
  124.  
  125.  
  126. public static class Person {
  127.  
  128. private final SimpleStringProperty firstName;
  129. private final SimpleStringProperty lastName;
  130. private final SimpleStringProperty email;
  131.  
  132. private Person(String fName, String lName, String email) {
  133. this.firstName = new SimpleStringProperty(fName);
  134. this.lastName = new SimpleStringProperty(lName);
  135. this.email = new SimpleStringProperty(email);
  136. }
  137.  
  138. public String getFirstName() {
  139. return firstName.get();
  140. }
  141.  
  142. public void setFirstName(String fName) {
  143. firstName.set(fName);
  144. }
  145.  
  146. public String getLastName() {
  147. return lastName.get();
  148. }
  149.  
  150. public void setLastName(String fName) {
  151. lastName.set(fName);
  152. }
  153.  
  154. public String getEmail() {
  155. return email.get();
  156. }
  157.  
  158. public void setEmail(String fName) {
  159. email.set(fName);
  160. }
  161. }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement