如何搜索通过jtextfield输入的值?
这是jtable的成功代码:
private JTable table;
private DefaultTableModel tableModel;
private JPanel centerPanel;
public JPanel centerPanel() {
centerPanel = new JPanel();
centerPanel.setBorder(BorderFactory.createLineBorder(Color.RED));
String col[] = { "Roll Number", "Full Name", "Gender" };
tableModel = new DefaultTableModel( col, 0 );
table = new JTable( tableModel );
table.setBorder(BorderFactory.createLineBorder(Color.RED));
for( Student student : students ) {
Object[] obj = { student.getRollNumber(), student.getName(), student.getGender() };
tableModel.addRow(obj);
}
centerPanel.add(table);
return centerPanel;
}
我正在寻找如何通过JTable
从JTextfield
进行搜索。
学生模型(Java类)
public class Student {
private String rollNumber;
private String name;
private String gender;
public Student(String rollNumber, String name, String gender) {
this.rollNumber = rollNumber;
this.name = name;
this.gender = gender;
}
public String getRollNumber() {
return rollNumber;
}
public void setRollNumber(String rollNumber) {
this.rollNumber = rollNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
@Override
public String toString() {
return "Student [rollNumber=" + rollNumber + ", name=" + name + ", gender=" + gender + "]";
}}
这是我用来在jtable中插入数据的学生模型