I have a JTable within my application and utilizing a class that extends AbstractTableModel to display the columns and data. However, the columns are not being displayed. I simply created a array of Strings and passed that array to getColumnName method do display the columns. But it is not working. Do I need to implment an instance of TableColumnModel as well? If not, any ideas on what can be wrong ? Thanks
Here's the relevant code:
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
public class VerbTableModel extends AbstractTableModel {
final String[] columnNames = {"Present", "Present Subjunctive", "Future", "Conditional", "Preterite", "Imperfect"};
String[][] cellData = new String[columnNames.length][6];
public boolean isCellEditable(int row, int col){
return false;
}
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return cellData.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
}
This code goes into my class where I display the GUI and where the table exists:
JPanel tablePanel = new JPanel();
tablePanel.setLayout(new FlowLayout());
tm = new VerbTableModel();
JTable verbTable = new JTable(tm);
tablePanel.add(verbTable);