Sembra che sia riuscito a settare l'Object[][], ma mi da errore per la JTable.....
Classe della grafica della JTable.....
codice:
package grafica;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTable;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.table.TableModel;
import database.RegistroCassa;
public class RegistroGraf extends JFrame {
/**
*
*/
private static final long serialVersionUID = -7576128986849460543L;
private JTable table;
public RegistroGraf(RegistroCassa registro) {
super("REGISTRO CASSA");
Object[] columnHeaders = {"ID","OPERAZIONE","IMPORTO","DATA","MOTIVO","CATEGORIA","SALDO"};
Object[][] rowData = registro.getRowData();
System.out.println(rowData.length);
System.out.println(rowData[2][2]);
this.table = new JTable(rowData, columnHeaders);
this.table.setFillsViewportHeight(true);
this.table.addMouseListener(
new MouseAdapter() { @Override
public void mouseClicked(MouseEvent event) {
JTable table = (JTable)event.getSource();
TableModel model = table.getModel();
int nRow = model.getRowCount();
int nCol = model.getColumnCount();
System.out.println(nRow);
System.out.println(nCol);
for(int i = 0; i < nRow ; i++) {
for(int j = 0; j < nCol; j++) {
String colName = model.getColumnName(j);
Object value = model.getValueAt(i, j);
System.out.println(colName + "=" + value);
}
System.out.println();
}
}
}
);
this.getContentPane().add(new JScrollPane(this.table));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300, 300);
this.setLocationRelativeTo(null);
}
} //FINE CLASSE
.... e la classe (RegistroCassa) che passa i valori a rowData
codice:
package database;
import java.sql.ResultSet;
import java.sql.SQLException;
public class RegistroCassa {
Database registro = new Database();
private ResultSet dati;
private String[] id, inout, importo, data, motivo, categoria, saldo;
public RegistroCassa() {
}
public void setDati() throws SQLException {
dati = registro.readDB("SELECT * FROM registro");
String xId = "";
String xInout = "";
String xImporto = "";
String xData = "";
String xMotivo = "";
String xCategoria = "";
String xSaldo = "";
try {
while (dati.next()) {
xId += dati.getString("ID")+"|";
xInout += dati.getString("inOut")+"|";
xImporto += dati.getString("importo")+"|";
xData += dati.getString("data")+"|";
xMotivo += dati.getString("motivo")+"|";
xCategoria += dati.getString("categoria")+"|";
xSaldo += dati.getString("saldo")+"|";
}
} catch (SQLException e) {
System.err.println(e.getMessage());
}
setId(xId.split("\\|"));
setInout(xInout.split("\\|"));
setImporto(xImporto.split("\\|"));
setData(xData.split("\\|"));
setMotivo(xMotivo.split("\\|"));
setCategoria(xCategoria.split("\\|"));
setSaldo(xSaldo.split("\\|"));
registro.readClose();
}
public Object[][] getRowData() {
for (int i=0; i<getIdElenco().length; i++) {
rowData[i] = {{id[i]},{inout[i]},{Importo[i]},{data[i]},{motivo[i]},{categoria[i]},{saldo[i]}};
}*/
Object[][] rowData = {getIdElenco(),getInoutElenco(),getImportoElenco(),getDataElenco(),getMotivoElenco(),
getCategoriaElenco(),getSaldoElenco()};
return rowData;
}
............
e questo è l'errore che mi da senza visualizzare la JTable
codice:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 3
at javax.swing.JTable$1.getValueAt(Unknown Source)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JViewport.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at java.awt.Window.paint(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$700(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Purtroppo non capisco dov'è l'errore!!!! 
Grazie per l'attenzione, saluti