I'm using a renderer to make a JTable
in Java NetBeans with multiple rows in a cell (Line Wrapping).
What I need to do, is that the user be able do some format to the cell, like Tab's and Enter's in the Text, when you use a Text Area without render, it does it like the way I want, it doesn't move between other controllers with this key events, the problem is when it gets rendered, if you press Enter, its like an accept event, and tab moves between controls. I think that there's still some properties that should be configured at the renderer for the text area component.
Here's the code I'm using for the rendering:
public class TableCellLongTextRenderer extends JTextArea implements TableCellRenderer{
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
this.setText((String)value);
this.setWrapStyleWord(true);
this.setLineWrap(true);
this.setRows(10);
//set the JTextArea to the width of the table column
setSize(table.getColumnModel().getColumn(column).getWidth(),getPreferredSize().height);
if (table.getRowHeight(row) != getPreferredSize().height) {
//set the height of the table row to the calculated height of the JTextArea
table.setRowHeight(row, getPreferredSize().height);
}
return this;
}
}
And here's how I use it:
table1.getColumnModel().getColumn(0).setCellRenderer(
new FAgregarArticulos.TableCellLongTextRenderer ());