无需
User在创建模型之前拆分对象,而是将其直接添加到模型中并允许模型为您完成工作…
例如
public class VstTableItemModel extends AbstractTableModel { private List<User> users; public VstTableItemModel(List<User> users) { this.users = new ArrayList<User>(users); } @Override public int getRowCount() { return users.size(); } @Override public int getColumnCount() { return 6; } @Override public Object getValueAt(int rowIndex, int columnIndex) { Object value = "??"; User user = users.get(rowIndex); switch (columnIndex) { case 0: value = user.getUserUsername(); break; case 1: value = user.getUserName(); break; case 2: value = user.getUserPhone(); break; case 3: value = user.getUserNic(); break; case 4: value = user.getUserAddress(); break; case 5: value = user.getUserEmail(); break; } return value; } @Override public Class<?> getColumnClass(int columnIndex) { return // Return the class that best represents the column... } public User getUserAt(int row) { return users.get(row); }}
这样,您应该能够执行类似…
List<User> userList = userManagerService.getAllUsers();VstTableItemModel tiModel = new VstTableItemModel(userList);
现在,当您需要…时,您可以抓住在特定行中代表的用户…
User user = tiModel.getUserAt(rowIndex);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)