Добавление наблюдаемого списка в таблицу в JavafxJAVA

Программисты JAVA общаются здесь
Anonymous
Добавление наблюдаемого списка в таблицу в Javafx

Сообщение Anonymous »

Я все еще новичок в работе в среде Javafx, и я пытаюсь сделать приложение системы управления MVC. В настоящее время я не получаю никаких проблем при запуске моего приложения, однако таблица не заполняется ни одним из объектов из списка массивов. Проблема с тем, как я звоню в GetCurrentList ()? Приносим извинения, если это очевидно, но любая помощь ценится.
import au.edu.uts.ap.javafx.*;

import javafx.fxml.*;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.event.ActionEvent;
import javafx.scene.Parent;
import javafx.scene.Node;
import javafx.scene.control.TableView;
import javafx.scene.control.TableColumn;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.ObservableList;
import javafx.scene.control.TableView.TableViewSelectionModel;
import javafx.scene.control.cell.PropertyValueFactory;
import model.Student;
import javafx.beans.property.*;

public class FacultyController extends Controller {

public ObservableList studentsL;

private Stage stage;
private Scene scene;
private Parent root;

@FXML
private TableView studentTable;

@FXML
private TableColumn name;

@FXML
private TableColumn email;

@FXML
private TableColumn phone;

//Read Student List into Table
@FXML private void initialize(URL url, ResourceBundle resources){

model.Students studentList = new model.Students();
studentsL.equals(studentList.getCurrentList());

name.setCellValueFactory(new PropertyValueFactory("name"));
email.setCellValueFactory(new PropertyValueFactory("email"));
phone.setCellValueFactory(new PropertyValueFactory("phone"));

studentTable.setItems(studentsL);

}

faculty.fxml












































































student.java
package model;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class Student {
private StringProperty name;
private StringProperty email;
private StringProperty phone;
private StringProperty address;
private StringProperty ID;
private StringProperty type;
private IntegerProperty credits;
private DoubleProperty payPerCredit;
private DoubleProperty totalFee;
private DoubleProperty scholarship;
private DoubleProperty netFee;
private DoubleProperty deduction;
private DoubleProperty deductionRate;
private Faculty faculty;

public Student(String name, String email, String phone, String address, String ID, String type, int credits, double scholarship, String deductionCode) {
this.name = new SimpleStringProperty();
this.name.set(name);
this.email = new SimpleStringProperty();
this.email.set(email);
this.phone = new SimpleStringProperty();
this.phone.set(phone);
this.address = new SimpleStringProperty();
this.address.set(address);
this.ID = new SimpleStringProperty();
this.ID.set(ID);
this.type = new SimpleStringProperty();
this.type.set(type);
this.credits = new SimpleIntegerProperty();
this.credits.set(credits);
this.payPerCredit = new SimpleDoubleProperty();
this.payPerCredit.set(500.00);
this.totalFee = new SimpleDoubleProperty();
this.totalFee.bind(this.credits.multiply(this.payPerCredit));
this.scholarship = new SimpleDoubleProperty();
this.scholarship.set(scholarship);
this.deductionRate = new SimpleDoubleProperty();
this.deductionRate.set(0.10);
this.deduction = new SimpleDoubleProperty();
if (deductionCode.equals("2022AUT"))
this.deduction.bind(this.totalFee.multiply(this.deductionRate));
else
this.deduction.set(0.00);
this.netFee = new SimpleDoubleProperty();
this.netFee.bind(this.totalFee.subtract(deduction).subtract(scholarship));

}

public void updateDetails(String name, String email, String phone, String address, String ID, String type, int credits, double scholarship, String deductionCode){
this.name.set(name);
this.email.set(email);
this.phone.set(phone);
this.address.set(address);
this.ID.set(ID);
this.type.set(type);
this.credits.set(credits);
this.scholarship.set(scholarship);
if (deductionCode.equals("2022AUT"))
this.deduction.bind(this.totalFee.multiply(this.deductionRate));
else
this.deduction.set(0.00);
}

public void setFaculty(Faculty e){
this.faculty = e;
}

public Faculty getFaculty(){
return this.faculty;
}

public ReadOnlyStringProperty nameProperty() {
return name;
}

public String getName(){
return name.getValue();
}

public ReadOnlyStringProperty emailProperty() {
return email;
}

public String getEmail(){
return email.getValue();
}

public ReadOnlyStringProperty phoneProperty() {
return phone;
}

public String getPhone(){
return phone.getValue();
}

public ReadOnlyStringProperty addressProperty() {
return address;
}

public String getAddress(){
return address.getValue();
}

public ReadOnlyStringProperty IDProperty() {
return ID;
}

public String getID(){
return ID.getValue();
}

public ReadOnlyStringProperty typeProperty() {
return type;
}

public String getType(){
return type.getValue();
}

public IntegerProperty creditsProperty() {
return credits;
}

public int getCredits(){
return credits.get();
}

public ReadOnlyDoubleProperty payPerCreditProperty() {
return payPerCredit;
}

public double getPayPerCredit(){
return payPerCredit.get();
}

public ReadOnlyDoubleProperty totalFeeProperty() {
return totalFee;
}

public double getTotalFee(){
return totalFee.get();
}

public ReadOnlyDoubleProperty netFeeProperty() {
return netFee;
}

public double getNetFee(){
return netFee.get();
}

public ReadOnlyDoubleProperty scholarshipProperty() {
return scholarship;
}

public double getScholarship(){
return scholarship.get();
}

public ReadOnlyDoubleProperty deductionProperty() {
return deduction;
}

public double getDeduction(){
return deduction.get();
}

public ReadOnlyDoubleProperty deductionRateProperty() {
return deductionRate;
}

public double getDeductionRate(){
return deductionRate.get();
}

public boolean hasName(String name){
return getName().toLowerCase().contains(name.toLowerCase().trim());
}

public boolean hasEmail(String email){
return getEmail().toLowerCase().contains(email.toLowerCase().trim());
}

public boolean deleteStudent() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}


students.java
package model;

import java.util.ArrayList;
import java.util.List;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;

public class Students {

private ObservableList students;
private ObservableList current;

public Students() {
current = FXCollections.observableArrayList();
students = FXCollections.observableArrayList(
new Student("Thomas Muller", "thomas.muller@uts.com", "99991111", "3 Byern St. Sydney 2001", "13697480", "Full-Time", 48, 4000, ""),
new Student("Alice Stefan", "alice.stefan@uts.com", "88881111", "24 Pitt St. Sydney 2001", "14517880", "Part-Time", 24,0, ""),
new Student("Lucy Lu", "lucy.lu@uts.com", "98981100", "11 Hunter St. Sydney 2100", "13267102", "Full-Time", 48,0, "2022AUT"),
new Student("Andreas Brehme", "andreas.b@uts.com", "90001222", "91 Sussex St. Sydney 2100", "13678020", "Full-Time", 48,0, ""),
new Student("Ruddy Voller", "ruddy.v@uts.com", "98980000", "15 Stan St. Sydney 2100", "13972870", "Full-Time", 48,8000, ""),
new Student("Monica Shwarz", "monica.s@uts.com", "92241188", "155 Jones St. Sydney 2001", "13859610", "Part-Time", 24,0, "2022AUT")
);
current.addAll(students);
students.addListener(new ListChangeListener() {
@Override
public void onChanged(javafx.collections.ListChangeListener.Change

Подробнее здесь: https://stackoverflow.com/questions/722 ... -in-javafx

Вернуться в «JAVA»