TableCellRenderer too slow???

P

Peter

Hi
I have JTable and my TableCellRenderer is extends JPanel
implements TableCellRenderer, but the performance is too slow.

The TableModel is already optimised :

public class JGranttTableModel extends DefaultTableModel {
private String[] columnNames = {"1",
"2","3","4","5","6","7","8","9","a","b","c","d","e","f","10"};
Vector content = new Vector();

public JGranttTableModel() {
content = new Vector();

int x;
for (x=0;x<255;x++){
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
content.add(String.valueOf(x*2));
//content.add(new Color(255-x,255-x,0));
}
}

public int getColumnCount() {
return columnNames.length;
}

public String getColumnName(int col) {
return columnNames[col];
}

public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}

public boolean isCellEditable(int row, int col) {
return true;
}

public Object getValueAt(int row, int column) {
return content.get(row * getColumnCount() + column);
}

public void clearContent() {
content.clear();
this.fireTableDataChanged();
}

public int getRowCount() {
if (content!=null){
return content.size() / getColumnCount();
}else{
return 0;
}
}

public void addValue(Object newVal) {
content.add(newVal);
this.fireTableDataChanged();
}

public void setVector(Vector vector) {
content = vector;
}

public void setValueAt(Object newVal, int row, int column) {
content.set(row * getColumnCount() + column, newVal);
this.fireTableCellUpdated(column, row);
this.fireTableDataChanged();
}
}


Do you have other way to speed up the TableCellRenderer?

thanks
from Peter ([email protected])
 
D

Daniel Dyer

Hi
I have JTable and my TableCellRenderer is extends JPanel
implements TableCellRenderer, but the performance is too slow.

The TableModel is already optimised :

Did you mean to include the code for the renderer rather than the model?
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}

Just as an aside, are you sure you are always going to have at least one
row in your model? It might be safer to implement this method along the
same lines as the getColumnName method, with an array of Class objects, one
for each column.

Do you have other way to speed up the TableCellRenderer?

Show us the code.
 
C

Cyril Mrazek

I don't see any TableCellRenderer in your example. Also, the Vector
uses synchronized methods, its non-synchronized equivalent is
ArrayList.

Cyril Mrazek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top