tags:

views:

83

answers:

1

I'm working on a pretty simple Java app in order to learn more about JTables, TableModels, and custom cell renderers. The table is a simple table with 8 columns only with text in them. When you click on an "add" button, a dialog pops up and lets you enter the data for the columns.

Now to my problem. One of the columns (the last one) should allow for multiple lines of text. I'm already putting HTML into the field, but it is not wrapping. I did some research and looked into JTable#setRowHeight(). However, once I use setRowHeight, I can no longer add rows to the table. The data is put into the table model, but it does not show in the table. If I remove the setRowHeight line, then it adds data just fine.

Is there another step to adding data to my data model that I'm missing?

Thanks a lot!

+1  A: 

You have to replace the cell editor. The default cell editor is a JTextField, I don't believe that allows for text wrap. A JTextArea or similar component would allow you to do that.

As for setRowHeight() disallowing you from adding new rows, I've never heard that before. Can you provide more details? or at the very least the code you used? I'm not able to reproduce the results as I am able to continue to add new rows despite using setRowHeight().

badcodenotreat
Thanks for your reply. I figured it out. I needed to use fireTableDataChanged() when I add a new row. Thanks again for the reply!
Brent Parker