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 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.
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.