1
I’d like to know how to retrieve information from a line of mine JTable
, follows the code line of the same.
Usuarios operacao = new Usuarios();
DefaultTableModel tabela = new DefaultTableModel();
private void adicionarLinhas(String nome, String patente, String sessao, String email) {
this.tabela.addRow(new Object[]{nome, patente, sessao, email});
}
public void Executar() throws IOException, ClassNotFoundException {
ArrayList<UsuariosBase> usuarios2 = operacao.LeituraDeRegistros();
for (UsuariosBase registros : usuarios2) {
tabela = (DefaultTableModel) jTable1.getModel();
this.adicionarLinhas(registros.nome, registros.patente, registros.sessao, registros.email);
}
}
public void Listar() throws IOException, ClassNotFoundException {
operacao.RecuperadorDeNomes();
for (int i = 1; i < operacao.totalDeArquivos; i++) {
Executar();
}
}
I tried to apply the code but got an error: "Exception in thread "AWT-Eventqueue-0" java.lang.Arrayindexoutofboundsexception: -1 ", I created an operation: "public void Recovers() { int selectedRowIndex = jTable1.getSelectedRow(); int columnCount = jTable1.getColumnCount(); for (int i = 0; i < columnCount; i++) { System.out.println(table.getValueAt(selectedRowIndex, i)); } } " and applied on class initialization, you know where I went wrong?
– neto schneider
@netoschneider add a [mcve] editing the question, without it there is no way to test and see what could cause the error.
– user28595
I already solved my big one, I forgot I was using a for multiply the actions of the method Executor to add lines to jTable, now it is 100% working, you know tell me how I make the mouse click correspond to certain table item? Thank you very much!!!
– neto schneider
@netoschneider if the problem helped you, you can mark how accept the answer by clicking on the
v
on her left side, in this way, she will serve as a reference for doubts similar to her :)– user28595
@netoschneider getseletedrow already picks the selected line, did not understand his other doubt.
– user28595
I would like to know how I do to the program identify the mouse click to so pass the selection the line capture action.
– neto schneider
I already solved it, thank you very much!
– neto schneider