Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package view;
- import javafx.application.Application;
- import javafx.beans.property.SimpleStringProperty;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.geometry.Insets;
- import javafx.geometry.Orientation;
- import javafx.scene.Group;
- import javafx.scene.Node;
- import javafx.scene.Scene;
- import javafx.scene.control.Label;
- import javafx.scene.control.ScrollBar;
- import javafx.scene.control.TableColumn;
- import javafx.scene.control.TableView;
- import javafx.scene.control.TextField;
- import javafx.scene.control.cell.PropertyValueFactory;
- import javafx.scene.layout.VBox;
- import javafx.scene.text.Font;
- import javafx.stage.Stage;
- public class UserListView extends Application {
- private TableView<Person> table = new TableView<Person>();
- private int start = 0, s = 0;
- private int step = 1;
- private final ObservableList<Person> data = FXCollections.observableArrayList();
- /* new Person("Jacob", "Smith", "jacob.smith@example.com"),
- new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
- new Person("Ethan", "Williams", "ethan.williams@example.com"),
- new Person("Emma", "Jones", "emma.jones@example.com"),
- new Person("Michael", "Brown", "michael.brown@example.com"),
- new Person("Michael", "Brown", "michael.brown@example.com")
- );*/
- public static void main(String[] args) {
- launch(args);
- }
- private void populateInitialList() {
- data.add(new Person("Jacob", "Smith", "jacob.smith@example.com"));
- data.add(new Person("Isabella", "Johnson", "isabella.johnson@example.com"));
- data.add(new Person("Ethan", "Williams", "ethan.williams@example.com"));
- data.add(new Person("Emma", "Jones", "emma.jones@example.com"));
- data.add(new Person("Michael", "Brown", "michael.brown@example.com"));
- data.add(new Person("Emma", "Jones", "emma.jones@example.com"));
- data.add(new Person("Emma", "Jones", "emma.jones@example.com"));
- }
- @Override
- public void start(Stage stage) {
- stage.setTitle("Table View Sample");
- stage.setWidth(450);
- stage.setHeight(200);
- final Label label = new Label("Address Book");
- label.setFont(new Font("Arial", 20));
- TableColumn<Person, String> firstNameCol = new TableColumn<Person, String>("First Name");
- firstNameCol.setMinWidth(100);
- firstNameCol.setCellValueFactory(
- new PropertyValueFactory<Person, String>("firstName"));
- TableColumn<Person, String> lastNameCol = new TableColumn<Person, String>("Last Name");
- lastNameCol.setMinWidth(100);
- lastNameCol.setCellValueFactory(
- new PropertyValueFactory<Person, String>("lastName"));
- TableColumn<Person, String> emailCol = new TableColumn<Person, String>("Email");
- emailCol.setMinWidth(200);
- emailCol.setCellValueFactory(
- new PropertyValueFactory<Person, String>("email"));
- populateInitialList();
- table.setItems(data);
- table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
- Scene scene = new Scene(table);
- stage.setScene(scene);
- stage.show();
- ScrollBar tableViewScrollBar = getTableViewScrollBar(table);
- tableViewScrollBar.valueProperty().addListener((observable, oldValue, newValue) -> {
- double position = newValue.doubleValue();
- ScrollBar scrollBar = getTableViewScrollBar(table);
- if (position == scrollBar.getMax()) {
- if (step <= 50) {
- data.add(new Person("Emma", "Jones", "emma.jones@example.com"));
- //listItems.addAll(r);
- //System.out.println("start " + start + " " + "step " + step);
- start = step;
- step += 1;
- /*
- * listItems.remove(0); listItems.remove(0);
- * listItems.remove(0); listItems.remove(0); s+=4;
- */
- scrollBar.decrement();
- }
- } else if (position == scrollBar.getMin()) {
- /*
- * if(s > 0){ step = start; start -= 4; s -= 4; listItems.add(0,
- * bigData.get(s)); listItems.add(1, bigData.get(s+1));
- * listItems.add(2, bigData.get(s+2)); listItems.add(3,
- * bigData.get(s+3)); listItems.remove(listItems.size()-1);
- * listItems.remove(listItems.size()-1);
- * listItems.remove(listItems.size()-1);
- * listItems.remove(listItems.size()-1); scrollBar.increment();
- * System.out.println("hiiii"); }
- */
- }
- });
- }
- private ScrollBar getTableViewScrollBar(TableView<?> tab) {
- ScrollBar scrollbar = null;
- for (Node node : tab.lookupAll(".scroll-bar")) {
- if (node instanceof ScrollBar) {
- ScrollBar bar = (ScrollBar) node;
- if (bar.getOrientation().equals(Orientation.VERTICAL)) {
- scrollbar = bar;
- }
- }
- }
- return scrollbar;
- }
- public static class Person {
- private final SimpleStringProperty firstName;
- private final SimpleStringProperty lastName;
- private final SimpleStringProperty email;
- private Person(String fName, String lName, String email) {
- this.firstName = new SimpleStringProperty(fName);
- this.lastName = new SimpleStringProperty(lName);
- this.email = new SimpleStringProperty(email);
- }
- public String getFirstName() {
- return firstName.get();
- }
- public void setFirstName(String fName) {
- firstName.set(fName);
- }
- public String getLastName() {
- return lastName.get();
- }
- public void setLastName(String fName) {
- lastName.set(fName);
- }
- public String getEmail() {
- return email.get();
- }
- public void setEmail(String fName) {
- email.set(fName);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement