Salve a tutti io ho questo codice e se lo si prova noterete che alle volte quando si clikka su una cella stampa 2 volte lo stesso valore.. PERCHE? sto impazzendo aiuto
<CODE>
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
public class CellSelectionExample implements ListSelectionListener {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){
public void run() {
new CellSelectionExample().go();
}
});
}
void go() {
JFrame f = new JFrame("CellSelectionExample");
f.getContentPane().add(new JScrollPane(createTable()));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
JTable createTable() {
table.setCellSelectionEnabled(true);
table.setSelectionMode(ListSelectionModel.SINGLE_S ELECTION);
table.getSelectionModel().addListSelectionListener (this);
table.getColumnModel().getSelectionModel().addList SelectionListener(this);
return table;
}
@Override()
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
System.out.format("(%2d,%2d)%n",
table.getSelectedColumn(), table.getSelectedRow());
}
}
private JTable table = new JTable(20,10);
}
</CODE>