gpt4 book ai didi

swing - Jgoodies JTable Binding,Swing

转载 作者:行者123 更新时间:2023-12-04 05:59:03 25 4
gpt4 key购买 nike

任何人都可以提供 jgoodies Jtable 绑定(bind)简单示例,使用 Swing 获取扩展 Jgoodies Model 类的 javabean 列表。我找不到一个简单的示例。

提前致谢

最佳答案

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

例如,您有一个 java bean,例如

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

}

希望这可以帮助。

关于swing - Jgoodies JTable Binding,Swing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9138396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com