有人可以帮我解决这个问题吗?
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e){
if(e.getValueIsAdjusting()){
ListSelectionModel model = table.getSelectionModel();
int lead = model.getLeadSelectionIndex();
displayRowValues(lead);
}
}
private void displayRowValues(int rowIndex){
String country = "";
Object oCountry = table.getValueAt(rowIndex, 0);
country += oCountry.toString();
countryTxt.setText(country );
}
});
选择一个行时,它应该从jtable(表)中的单元格(表)中将数据发送到textfield(countrytxt),但是只有当我单击行时,当我用箭头骑自行车时,它才能起作用 key 。
最佳答案
问题出在这一行:
if (e.getValueIsAdjusting()) {
将其替换为:
if (e.getValueIsAdjusting()) return;
顺便说一句,这是对多重选择事件的检查。
关于java - 从 jtable 更新 jtextfield,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11637273/