public class MyTableCellRenderer extends JTextArea implements TableCellRenderer
{
public MyTableCellRenderer() {
setLineWrap(false);
setWrapStyleWord(true);
setEditable(true);
setOpaque(true);
}
public KeyListener keyListener = new KeyAdapter() {
public void keyTyped(KeyEvent e) {
System.out.println("JAWWWWWOOOOOOOOOOOOOOOOOOOOOHL");
/* //Zeilenhöhe anpassen
if (table.getRowHeight()!= (int) this.getMinimumSize().height)
table.setRowHeight(row, (int) this.getMinimumSize().height); */
}
};
public Component getTableCellRendererComponent(JTable table, Object obj, boolean isSelected,
boolean hasFocus, int row, int column) {
if (isSelected)
{
setForeground(table.getSelectionForeground());
setBackground(table.getSelectionBackground());
}
else
{
setForeground(table.getForeground());
setBackground(table.getBackground());
}
setFont(table.getFont());
if (hasFocus)
{
setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
if (table.isCellEditable(row, column))
{
setForeground( UIManager.getColor("Table.focusCellForeground") );
setBackground( UIManager.getColor("Table.focusCellBackground") );
}
}
else
{
setBorder(new EmptyBorder(1, 2, 1, 2));
}
//Text in die Textarea schreiben
setText((obj == null) ? "" : obj.toString());
addKeyListener(keyListener);
return this;
}
}