Reputation: 1592
I'm developing an app which has an JTable that needs to have multiline cells. Therefore I extended JTextArea and everything is shown noce, but when I try to edit a cell. the text is shown in a single line, and becomes multilined after edit. I want the text to stay multilined during editting. Is there a way to do that?
Upvotes: 2
Views: 2004
Reputation: 5267
Create your TableCellEditor using a JTextArea (instead of the default behaviour which uses JTextField) and set it to your JTable.
You can use a JEditorPane as well to support text styling, if you wish.
---- Edit2 ----
New TableCellEditor:
class MyTableCellEditor extends AbstractCellEditor implements TableCellEditor {
JComponent component = new JTextArea();
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
int rowIndex, int vColIndex) {
((JTextArea) component).setText((String) value);
return component;
}
public Object getCellEditorValue() {
return ((JTextArea) component).getText();
}
}
Upvotes: 8