从jtable更新jtextfield

Bra*_*zic 1 java swing jtable listener listselectionlistener

有人能帮助我听这个听众吗?

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 );
    }
});
Run Code Online (Sandbox Code Playgroud)

当选择其中一行时,它应该将jtable(table)中的单元格中的数据发送到textfield(countryTxt),但只有当我点击行而不是当我用箭头键循环我的表时才能工作.

Rei*_*eus 5

问题出在这一行:

if (e.getValueIsAdjusting()) { 
Run Code Online (Sandbox Code Playgroud)

将其替换为:

if (e.getValueIsAdjusting()) return;
Run Code Online (Sandbox Code Playgroud)

这是对多个选择事件BTW的检查.