O codigo abaixo exibe o jtable as com os dados do array de String - no lugar do array quero os dados do banco de dados mas quando tento trabalhar com o banco de dados tenho de trabalhar com o vector e daí não estou sabendo retornar os dados para o objeto jtable
public class TablePanel extends JPanel {
TablePanel() {
setLayout (new BorderLayout());
// Create data model
EmployeeDataModel employeeModel = new EmployeeDataModel();
// Create/setup table
JTable table = new JTable (employeeModel);
// Place table in JScrollPane
JScrollPane scrollPane = new JScrollPane (table);
// Add to Screen
add(scrollPane, BorderLayout.CENTER);
}
}
class EmployeeDataModel extends AbstractTableModel {
// By extending AbstractTableModel, instead of
// implementing TableModel yourself,
// AbstractTableModel takes care of
// TableModelListener list management
[b]Exatamente aqui eu quero pegar os dados do banco de dados como :?: :?:
String columns[] = {“Employee ID”, “First Name”,
“Last Name”, “Department”};
String rows[][] = {
{“0181”, “Bill”, “Cat”, “Political Candidate”},
{“0915”, “Opus”, “Penguin”, “Lost and Found”},
{“1912”, “Milo”, “Bloom”, “Reporter”},
{“3182”, “Steve”, “Dallas”, “Legal”},
{“4104”, “Hodge”, “Podge”, “Style”},
{“5476”, “Billy”, “Boinger”, “Entertainment”},
{“6289”, “Oliver”, “Jones”, “Science”},
{“7268”, “Cutter”, “John”, “Travel”},
{“8133”, “W. A.”, “Thornhump”, “C.E.O”},
{“9923”, “Berke”, “Breathed”, “Editor”}
};[/b]
private int numColumns = columns.length;
private int numRows = rows.length;
public int getColumnCount() {
return numColumns;
}
public int getRowCount() {
return numRows;
}
public Object getValueAt (int row, int column) {
return rows[row][column];
}
public String getColumnName (int columnIndex) {
return columns[columnIndex];
}
public void setValueAt (Object aValue,
int row, int column) {
String cellValue;
if (aValue instanceof String)
cellValue = (String)aValue;
else
cellValue = aValue.toString();
rows[row][column] = cellValue;
fireTableCellUpdated (row, column);
}
public boolean isCellEditable(int row, int column) {
// first column is read-only
return (column != 0);
}
}
