Jgoodies JTable Binding,Swing



任何人都能提供jgoodies Jtable绑定的简单例子吗?使用swing,以扩展jgoodies Model类的javabeans列表为例。我找不到一个简单的例子

提前感谢

对于JTable绑定,您需要为您的JTable 编写一个TableModel

例如,您有一个javabean,例如

public class Employee {
     private String employeeName;
     private String employeeNumber;
     // And the getters and setters for both the variables
}

创建一个表,

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));

MyTableModel类以list作为参数,它将扩展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();
    } 
}
}

希望这能有所帮助。

相关内容

  • 没有找到相关文章

最新更新