This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes MultiLine JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "MultiLine JTable" Watch "MultiLine JTable" New topic
Author

MultiLine JTable

Robin Gray
Greenhorn

Joined: Aug 28, 2002
Posts: 8
Hi
I am trying to implement a MultiLine Editable JTable without much luck.
I have tried to write my own but can't get close to a working version.
I have managed to find the following code : MultiLine Cell Renderer and Editor
which works fantastic. The code is really simple except there is one small problem, when a String longer than the cell width is inserted, it does not wrap to the next line unless you edit the cell!
I have traced the bug down to the following method in MultiLineCellEditor:
private int cellHeight(int row,int col) {
if (row == table.getEditingRow() && col == table.getEditingColumn())
return textArea.getPreferredSize().height;
else
return table.getDefaultRenderer(String.class).getTableCellRendererComponent(table,
table.getModel().getValueAt(row,col),false,false,row,col).getPreferredSize().height;
}
This method is called after initialisation of the table but it doesn't return the right value when used at this point whereas it works after that. The reason is that the JTextArea which is returned by
table.getDefaultRenderer(String.class).getTableCellRendererComponent(table,table.getModel().getValueAt(row,col),false,false,row,col)
does not seem to have yet its final width and therefore when asked about its prefered height gets the wrong result.
If anyone can figure out a work around for this bug or has a working solution for a MultiLine Editable JTable it would be appreciated
Robin
MultiLine Cell Renderer and Editor
 
 
subject: MultiLine JTable
 
Similar Threads
Right Align numbers in Jtable
JRadioButton in JTable
Tabbing between cells in a JTable
problem in JTable
MultiLine JTable