我想渲染一个调整行高度的swing表,具体取决于列中显示的文本数量,以便所有文本显示在单元格中。
问题在于,当我将高度设置为行时,会创建一个无限循环。我怎么能解决它?
这是我的渲染器
final class RenderTextAreaMessage extends DefaultTableCellRenderer {
JTextArea textareaMessage;
@Override
public Component getTableCellRendererComponent(JTable aTable, Object aNumberValue, boolean aIsSelected,
boolean aHasFocus, int aRow, int aColumn ) {
System.out.println("aa");
String value = (String)aNumberValue;
textareaMessage = new JTextArea();
textareaMessage.setLineWrap(true);
textareaMessage.setWrapStyleWord(true);
textareaMessage.setText(value);
textareaMessage.setBorder(null);
textareaMessage.setMargin(null);
Component renderer = super.getTableCellRendererComponent(
aTable, aNumberValue, aIsSelected, aHasFocus, aRow, aColumn
);
Font fontType = textareaMessage.getFont();
FontMetrics fontMet = textareaMessage.getFontMetrics(fontType);
int fheight = fontMet.getHeight();
int lineCount = textareaMessage.getLineCount();
int rowHeight = lineCount * fheight;
aTable.setRowHeight(aRow,rowHeight+6);
return textareaMessage;
}
}