@FXML
TableView<User_Info> table;
@FXML
TableColumn<User_Info, String> name;
@FXML
TableColumn<User_Info, String> username;
@FXML
TableColumn<User_Info, String> contact;
@FXML
TableColumn<User_Info, String> key;
@FXML
TableColumn<User_Info, String> mac;
public ObservableList<User_Info> list = FXCollections.observableArrayList(User_Info.fetch_List());
// Event Listener on Button.onAction
@FXML
public void delete_user(ActionEvent event) {
// TODO Autogenerated
}
@Override
public void initialize(URL location, ResourceBundle resources) {
// TODO Auto-generated method stub
name.setCellValueFactory(new PropertyValueFactory<User_Info, String>("Name"));
username.setCellValueFactory(new PropertyValueFactory<User_Info, String>("Username"));
contact.setCellValueFactory(new PropertyValueFactory<User_Info, String>("Contact"));
key.setCellValueFactory(new PropertyValueFactory<User_Info, String>("Key"));
mac.setCellValueFactory(new PropertyValueFactory<User_Info, String>("Mac"));
table.setItems(list);
}
这是我的控制器,我在其中插入tableview和列
public class User_Info {
static ArrayList<User_Info> list = new ArrayList<User_Info>();
public String iName;
public String iUsername;
public String iContact;
public long iKey;
public long iMac;
static LoginModel model = new LoginModel();
public User_Info(String iName, String iUsername, String iContact, long iKey, long iMac) {
this.iUsername = iName;
this.iUsername = iUsername;
this.iContact = iContact;
this.iKey = iKey;
this.iMac = iMac;
}
public static void prepareList() {
list.clear();
try {
Document document = Jsoup.connect("http://consonant-vicinity.000webhostapp.com/retrievedata.php")
.timeout(10000).post();
StringTokenizer str = new StringTokenizer(document.text(), " ");
while (str.hasMoreTokens()) {
String name = str.nextToken();
String username = str.nextToken();
String contact = str.nextToken();
Long key = Long.parseLong(str.nextToken());
Long mac = Long.parseLong(str.nextToken());
if (!username.equals(model.getUsername())) {
list.add(new User_Info(name, username, contact, key, mac));
}
}
} catch (Exception e) {
e.getMessage();
}
}
public static ArrayList<User_Info> fetch_List() {
return list;
}
public String get_Username() {
return iUsername;
}
public String get_Contact() {
return iContact;
}
public long get_Key() {
return iKey;
}
public String getName() {
// TODO Auto-generated method stub
return iName;
}
}
这是我的自定义类User_Info,这里prepare_list用于从某个服务器获取数据,我在main方法中调用此方法,所以只需从Admincontroller调用我的tableview存在的列表
输出:表中没有数据,所以我希望所有数据都应该是该表中的数据
所以请帮忙!