我试图找到一种解决问题的方法,实际上我有jtextfield,当我创建actionperforme时,我想创建一个表,其中的数据由jtextfield的值过滤并显示10行,然后单击在该行上,或按Enter键,将选定的行数据放在几个文本字段中。
JTable table;
DefaultTableModel model;
JScrollPane jsp;
String[] columns = {"First Name", "Surname", "Country", "Event", "Place", "Time", "World Record" };
Object[][] rows = {
{"César Cielo", "Filho", "Brazil", "50m freestyle",1 , "21.30", false },
{"Amaury", "Leveaux", "France", "50m freestyle", 2, "21.45", false },
{"Eamon", "Sullivan", "Australia", "100m freestyle", 2, "47.32", false },
{"Michael", "Phelps", "USA", "200m freestyle", 1, "1:42.96", false },
{"Ryan", "Lochte", "USA", "200m backstroke", 1, "1:53.94", true },
{"Hugues", "Duboscq", "France", "100m breaststroke", 3, "59.37", false }
};
public void table(){
model = new DefaultTableModel(rows, columns);
table = new JTable(model);
table.setSize(500, 150);
jsp = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.LINE_AXIS));
jPanel.add(table);
table.setLocation(txtSearch.getX(), txtSearch.getY()+30);
table.setVisible(true);
}
private void txtSearchKeyReleased(java.awt.event.KeyEvent evt) {
if(txtSearch.getText().isEmpty())
{
txtSearch.requestFocus();
}
else{
table();
}
}
有人可以帮我吗?