Can anyone provide jgoodies Jtable binding simple example using swing taking a List of javabeans extending Jgoodies Model class.I could not find a simple example of doing it.
For JTable binding, you need to write a TableModel for your JTable
For example, you have a java bean such as
public class Employee {
private String employeeName;
private String employeeNumber;
// And the getters and setters for both the variables
}
Create a table,
List <Employee> myList = new ArrayList<Employee>();
// add few Employee objects to this list and pass it into MyTableModel class
Jtable t1 = new Jtable();
t1.setModel(new MyTableModel(myList));
The class MyTableModel takes list as an argument and it will extend com.jgoodies.binding.adapter.AbstractTableAdapter
MyTableModel.java
public class MyTableModel extends AbstractTableAdapter<Employee> {
SelectionInList<Employee> listModel = new SelectionInList<Employee>();
public SourceCodeFolderTableAdapter(SelectionInList<Employee> listModel) {
super(listModel, new String [] {"Employee Name","Employee Number"});
this.listModel = listModel;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Employee emp = (Employee) getRow(rowIndex);
if (columnIndex == 0) {
return emp.getEmployeeName();
} else if (columnIndex == 1) {
return emp.getEmployeeNumber();
}
}
}
For JTable binding, you need to write a TableModel for your JTable
For example, you have a java bean such as
Create a table,
The class MyTableModel takes list as an argument and it will extend com.jgoodies.binding.adapter.AbstractTableAdapter
MyTableModel.java
Hope this helps.