Use a custom renderer. Extending JLabel
should give you ellipsis symbols to indicate truncation, but you can use JPanel
and this approach to let clipping chop the result.
Addendum: The WrapEditorKit
that you cited works well and seems to do what you want. In your LogRenderer
, I think you can extend JEditorPane
and set the editor in the constructor. For example:
private static class LogRenderer
extends JEditorPane implements TableCellRenderer {
public LogRenderer() {
this.setEditorKit(new WrapEditorKit());
}
public Component getListCellRendererComponent(
JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
this.setText((String) value);
return this;
}
@Override
public Component getTableCellRendererComponent(
JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
this.setText((String) value);
return this;
}
}
trashgod
2010-01-26 17:44:57