• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

MultiLine JTable

Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
return table.getDefaultRenderer(String.class).getTableCellRendererComponent(table,
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
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
MultiLine Cell Renderer and Editor
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic