• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextArea Editor in JTable

 
Anagha Medicharla
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want cells in JTable that takes multiline text. I have created two classes ,TextAreaEditor and TextAreaRenderer.I think there is a problem with TextAreaEditor class .When I type in one cell and go to other cell, conetent of previous cell disappears.
Cananybody help me out.
I have written the code as follows:
[code] class TextAreaEditor extends DefaultCellEditor {
protected JTextArea txt;
private String label;
public TextAreaEditor(JCheckBox checkBox) {
super(checkBox);
txt = new JTextArea();
txt.setOpaque(true);
txt.setLineWrap(true);
txt.setWrapStyleWord(true);
txt.setOpaque(true);

}
public Component getTableCellEditorComponent(JTable table, Object value,boolean isSelected, int row, int column) {

label = (value ==null) ? "" : value.toString();
txt.setText( label );
return txt;
}
public Object getCellEditorValue() {
return new String( label ) ;
}
public boolean stopCellEditing() {
return super.stopCellEditing();
}
protected void fireEditingStopped() {
super.fireEditingStopped();
}
}[\code]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!