« Oracle compra a SUN. E agora? | Home | DAVINCCI meu mais novo brinquedo »
Pegar linha de um JTable
de raydacosta | Sexta, 1 de Maio de 2009
Pegar linha de um JTable
jTable1 = new JTable(objeto, coluna);
ListSelectionModel selModel = jTable1.getSelectionModel();
selModel.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
int valorInt = jTable1.getSelectedRow();
String valor = jTable1.getValueAt(valorInt,0).toString();
}
}
});Outra forma:
private void listenerTable2(){
ListSelectionModel rowSM = jTableVistas.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e){
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty()) {
} else {
int selectedRow = lsm.getMinSelectionIndex();
setLinhaRemover(selectedRow);
String valor = String.valueOf(jTableVistas.getValueAt(selectedRow,0));
popularTelaVista(valor);
}
}
});this.eventoJTable2(jTableVistas);
}
Categorias: J2SE | | Enviar por e-mail | Hits para esta publicação: 337





