Results 1 to 4 of 4
- 03-21-2008, 08:47 AM #1
Member
- Join Date
- Mar 2008
- Posts
- 2
- Rep Power
- 0
Data from a model class won't show up in the table
I have a simple model class that's derived from AbstractTableModel, which looks like this:
the problem:Java Code:public class AddTrackModel extends AbstractTableModel { public AddTrackModel() { super(); content = new Object[10][9]; //10 rows, 9 columns for (int i = 0; i < 10; ++i) { content[i] = new Object[] { new Boolean(true), "","","","","","" }; // i'm adding data to the content array to be displayed on the table } this.fireTableDataChanged(); // fire a notification } public int getRowCount() { return 0; } public int getColumnCount() { return columns.length; } public Object getValueAt(int row, int col) { return content[row][col]; } public String getColumnName(int col) { return columns[col]; } private String[] columns = { "Check", "Artist", "Title", "CD No.", "Track No.", //"Album", //"Genre", //"BPM", //"Description" }; private static final int CHECKBOX = 0, ARTIST = 1, TITLE = 2, CDNUM = 3, TRACKNUM = 4, ALBUM = 5, GENRE = 6, BPM = 7, DESC = 8; private Object[][] content; }
data that i entered into the content[][] array does not show up in the table.
is there additional step i should do? all i know in order for the data to get displayed correctly is to implement the getValueAt which i did, in above code. And i even fired the fireTableDataChanged in the constructor right after i update the content[][] array, but the data still don't shows up in my table and i'm wondering why?
do i need to implement an additional listener in my table that handles the drawing? i'm still using the original JTable.
thank you very much! :)
- 03-21-2008, 04:18 PM #2
Java Code:public int getRowCount() { return content.length; }
- 03-22-2008, 11:15 AM #3
Member
- Join Date
- Mar 2008
- Posts
- 2
- Rep Power
- 0
that solved the problem. thank you!
- 11-27-2008, 08:20 PM #4
Member
- Join Date
- Nov 2008
- Posts
- 1
- Rep Power
- 0
Pretty much the same error
Hi,
I'm having a very similar problem but can't seem to figure out what exactly it is. I've got an Abstract Model Table that isn't showing anything in my JTable when I know that there is in fact a vector that is filled up with data. How do I make the JTable refresh so it displays the data. Did I also forget to add a certain function? Do I need a listener or a renderer? Here is my Abstract Model Table Class.
import java.util.Vector;
import javax.swing.table.AbstractTableModel;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
public class QueryTableModel extends AbstractTableModel{
/**
*
*/
public static final int BOTH = 0;
public static final int NONRECONCILED = 1;
public static final int RECONCILED =2;
Vector<String[]> cache;
String[] headers;
int colCount;
public QueryTableModel(){
super();
cache = new Vector<String[]>();
}
public String getColumnName(int i){
return headers[i];
}
public String[] getHeaders(){
return headers;
}
public int getColumnCount(){
return colCount;
}
public int getRowCount(){
return cache.size();
}
public Object getValueAt (int row, int col){
if(row < cache.size() && row >= 0 && col >= 0 && col < colCount){
return ((String[]) cache.elementAt(row))[col];
}
return null;
}
public Object getRow(int row){
return cache.elementAt(row);
}
public void setVector(ResultSet rs){
if(cache.isEmpty() == false){
cache.clear();
}
try{
ResultSetMetaData meta = rs.getMetaData();
colCount = meta.getColumnCount();
headers = new String[colCount];
for(int i=1; i<= colCount; i++){
headers[i-1] = meta.getColumnName(i);
}
while(rs.next()){
String[] record = new String[colCount];
for(int j=0; j<colCount; j++){
record[j] = rs.getString(j+1);
}
cache.addElement(record);
}
fireTableChanged(null);
//fireTableStructureChanged();
}catch (Exception e){
e.printStackTrace();
}
}
public void setVector(Vector<String[]> vect){
if(cache.isEmpty() == false){
cache.clear();
}
cache = (Vector<String[]>) vect.clone();
this.fireTableChanged(null);
//fireTableStructureChanged();
}
public void setHeaders(String[] head){
headers = head;
}
public void setColumn(int col){
colCount = col;
}
public Vector<String[]> getData(){
return (Vector<String[]>) cache.clone();
}
public void clear(){
cache.clear();
}
}
Any ideas would be greatly appreciated.
Similar Threads
-
Modifying data in database table using PreparedStatement
By Java Tip in forum Java TipReplies: 0Last Post: 02-09-2008, 08:22 PM -
Plz help ... retreiving data from an access database table....
By austinsmiles in forum New To JavaReplies: 1Last Post: 02-01-2008, 01:21 PM -
netbeans 6.0 not show commpunent or show blank page
By fahimaamir in forum NetBeansReplies: 1Last Post: 01-26-2008, 06:20 AM -
Data formatting for the <display:table>
By yuchuang in forum Web FrameworksReplies: 3Last Post: 12-14-2007, 10:52 AM -
Jsf, Filtering Data In A Table
By Freddie in forum JavaServer Faces (JSF)Replies: 2Last Post: 05-11-2007, 12:59 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks