wood burning stoves 2.0*
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
Author

JTable not working with tableChanged

Walk Rustin
Greenhorn

Joined: Aug 05, 2003
Posts: 9
Hi,
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.
thanks.
....
class StockTableData extends AbstractTableModel {}
......
table.setModel(m_data);
......
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);
table.addColumn(column);
}

...
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() {
setEditable(false);
setLineWrap(true);
setWrapStyleWord(true);
setBorder(m_noFocusBorder);
}
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int nRow, int nCol)
{
if (value instanceof ColorData) {
ColorData cvalue = (ColorData)value;
setText(cvalue.m_data.toString());
setBackground(isSelected && !hasFocus ?
table.getSelectionBackground() : table.getBackground());
setForeground(isSelected && !hasFocus ?
table.getSelectionForeground() : cvalue.m_color);
setFont(table.getFont());
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: 15286
    
    6

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 - A Test Data Generation Platform
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.
Ed


The nice thing about Standards is that there are so many to choose from!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable not working with tableChanged
 
Similar Threads
Related JTable Header
JTable GridLines - removing lines from certain cells
Adding/Removing rows from a JTable
erratic scrolling behavior with JTable with variable height rows
Color in JTable