• Post Reply Bookmark Topic Watch Topic
  • New Topic

how can i set Line wrap for a Column in JTable?  RSS feed

 
rahul kumar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some data which is actually a complaint description for computer. now the description on an average is 3-4 lines long apprx(50-60 words). It has to be shown in the Column , but it is very odd for the user to increase the size of the column to see the complete text, so tell me how can i wrap the text in the preferred size of the column.
Pls reply soon as i am running out of time , as my project's deadline is 25 march.
 
A P Rao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this
//
columnModel.getColumn(0).setCellRenderer(new TextTableRenderer);
table.setRowHeight(0, 80);
// ************* //
// class starts here
class TextTableRenderer extends JTextArea implements TableCellRenderer {
public TextTableRenderer() {
setOpaque(true);
setLineWrap(true);
setWrapStyleWord(true);
}

public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {

if (isSelected) {
setForeground(new Color(250, 0, 250));
setBackground(table.getSelectionBackground());
} else {
setForeground(new Color(80,90,155));
setBackground(table.getBackground());
}

setText((value == null)
? ""
: value.toString());
return this;
}
}

hope this will helps u
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!