Well after some searching, I finally got it, just copied some code from another answer, and used it in my example, heres the final code for anyone who needs a table with editable cells.
class TextAreaCellRenderer implements TableCellRenderer {
private JTextArea textArea = new JTextArea();
public TextAreaCellRenderer() {
super();
textArea.setLineWrap(true);
textArea.setBorder(BorderFactory.createEmptyBorder(1, 5, 1, 5));
}
@Override
public Component getTableCellRendererComponent(
JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
if (isSelected) {
textArea.setForeground(table.getSelectionForeground());
textArea.setBackground(table.getSelectionBackground());
} else {
textArea.setForeground(table.getForeground());
textArea.setBackground(table.getBackground());
}
textArea.setFont(table.getFont());
textArea.setText((value == null) ? "" : value.toString());
return textArea;
}
}
class TextAreaCellEditor implements TableCellEditor {
private final JScrollPane scroll;
private JTextArea textArea = new JTextArea();
public TextAreaCellEditor() {
scroll = new JScrollPane(textArea);
scroll.setBorder(BorderFactory.createEmptyBorder());
//scroll.setViewportBorder(BorderFactory.createEmptyBorder());
textArea.setLineWrap(true);
textArea.setBorder(BorderFactory.createEmptyBorder(1, 5, 1, 5));
KeyStroke enter = KeyStroke.getKeyStroke(
KeyEvent.VK_ENTER, InputEvent.CTRL_MASK);
textArea.getInputMap(JComponent.WHEN_FOCUSED).put(enter, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
stopCellEditing();
}
});
}
@Override
public Object getCellEditorValue() {
return textArea.getText();
}
@Override
public Component getTableCellEditorComponent(
JTable table, Object value, boolean isSelected, int row, int column) {
System.out.println("2. getTableCellEditorComponent");
textArea.setFont(table.getFont());
textArea.setText((value != null) ? value.toString() : "");
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
textArea.setCaretPosition(textArea.getText().length());
textArea.requestFocusInWindow();
System.out.println("4. invokeLater: getTableCellEditorComponent");
}
});
return scroll;
}
@Override
public boolean isCellEditable(final EventObject e) {
if (e instanceof MouseEvent) {
return ((MouseEvent) e).getClickCount() >= 2;
}
System.out.println("1. isCellEditable");
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
if (e instanceof KeyEvent) {
KeyEvent ke = (KeyEvent) e;
char kc = ke.getKeyChar();
if (Character.isUnicodeIdentifierStart(kc)) {
textArea.setText(textArea.getText() + kc);
System.out.println("3. invokeLater: isCellEditable");
}
}
}
});
return true;
}
//Copid from AbstractCellEditor
protected EventListenerList listenerList = new EventListenerList();
transient protected ChangeEvent changeEvent = null;
@Override
public boolean shouldSelectCell(EventObject e) {
return true;
}
@Override
public boolean stopCellEditing() {
fireEditingStopped();
return true;
}
@Override
public void cancelCellEditing() {
fireEditingCanceled();
}
@Override
public void addCellEditorListener(CellEditorListener l) {
listenerList.add(CellEditorListener.class, l);
}
@Override
public void removeCellEditorListener(CellEditorListener l) {
listenerList.remove(CellEditorListener.class, l);
}
public CellEditorListener[] getCellEditorListeners() {
return listenerList.getListeners(CellEditorListener.class);
}
protected void fireEditingStopped() {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == CellEditorListener.class) {
// Lazily create the event:
if (changeEvent == null) {
changeEvent = new ChangeEvent(this);
}
((CellEditorListener) listeners[i + 1]).editingStopped(changeEvent);
}
}
}
protected void fireEditingCanceled() {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == CellEditorListener.class) {
// Lazily create the event:
if (changeEvent == null) {
changeEvent = new ChangeEvent(this);
}
((CellEditorListener) listeners[i + 1]).editingCanceled(changeEvent);
}
}
}
}
Only have to copy those 2 classes, and use it in your table, like this:
'jTableName'.getColumnModel().getColumn('number of column you need to set editable').setCellRenderer(new 'principal class name'.TextAreaCellRenderer());
'jTableName'.getColumnModel().getColumn('number of column you need to set editable').setCellEditor(new 'principal class name'.TextAreaCellEditor());
Just change the commented parts, and that's it, hope it helps someone like it helped me, I used this link as base.
Custom CellEditor with JScrollPane - start editing issue