The moose likes Swing / AWT / SWT and the fly likes JTable not working with  tableChanged Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable not working with  tableChanged" Watch "JTable not working with  tableChanged" New topic

JTable not working with tableChanged

Walk Rustin

Joined: Aug 05, 2003
Posts: 9
I have a JTable and I use table model. I also use TableCellRenderer. Now when i use tableChange() method the method getValueAt(int nRow, int nCol) in the model is called recursively forever. It starts with row zero to row 7 and then starts again. I have spent quite some time on it and have been unable to solve it. Please help me.
class StockTableData extends AbstractTableModel {}
for (int k = 0; k < m_data.getColumnCount(); k++ ) {
System.out.println("k is " + k);
TableCellRenderer renderer = new TextAreaCellRenderer();
TableColumn column = new TableColumn(k, StockTableData.m_columns[k].m_width, renderer, null);

class TextAreaCellRenderer extends JTextArea implements TableCellRenderer {
protected static Border m_noFocusBorder = new EmptyBorder(1, 1, 1, 1);
protected static Border m_focusBorder = UIManager.getBorder("Table.focusCellHighlightBorder");
public TextAreaCellRenderer() {
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int nRow, int nCol)
if (value instanceof ColorData) {
ColorData cvalue = (ColorData)value;
setBackground(isSelected && !hasFocus ?
table.getSelectionBackground() : table.getBackground());
setForeground(isSelected && !hasFocus ?
table.getSelectionForeground() : cvalue.m_color);
setBorder(hasFocus ? m_focusBorder : m_noFocusBorder);
// Adjust row's height
int width = table.getColumnModel().getColumn(nCol).getWidth();
setSize(width, 1000);
int rowHeight = getPreferredSize().height;
System.out.println("-- ");
if (table.getRowHeight(nRow) != rowHeight)
table.setRowHeight(nRow, rowHeight);
return this;
// To fix JDK bug
public String getToolTipText(MouseEvent event) {
return null;

- Walk
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Walk Run
Welcome to Javaranch! We don't have too many rules around here but we do have a Naming Policy. Please adjust your display name accordingly.
You can change your display name here
Thanks and hope to see you around.

GenRocket - Experts at Building Test Data
Eddie Vanda
Ranch Hand

Joined: Mar 18, 2003
Posts: 281
Hi Walk,
class StockTableData extends AbstractTableModel {}

AbstractTableModel does not have any mechanism for storing data so you can't just extend it with an empty class. This would not compile because you need to provide the getValueAt and a couple of other methods yourself.
If you have written some code in your model StockTableData then that is most likely where the problem is.
If this does not make sense to you, then swap AbstractTableModel for DefaultTableModel and most of your problems should go away.

The nice thing about Standards is that there are so many to choose from!
I agree. Here's the link:
subject: JTable not working with tableChanged
It's not a secret anymore!