在网上找了些资料,
class TableCellTextAreaRenderer extends JTextArea implements TableCellRenderer {
public JTable extTable = null;
public TableCellTextAreaRenderer() {
setLineWrap(true);
setWrapStyleWord(true);
this.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (isSelected) {
this.setBackground(table.getSelectionBackground());
} else {
this.setBackground(table.getBackground());
}
int maxPreferredHeight = 26;
for (int i = 0; i < table.getColumnCount(); i++) {
setText("" + table.getValueAt(row, i));
setSize(table.getColumnModel().getColumn(column).getWidth(), 0);
maxPreferredHeight = Math.max(maxPreferredHeight, getPreferredSize().height);
}
if (table.getRowHeight(row) != maxPreferredHeight) {
table.setRowHeight(row, maxPreferredHeight);
}
setText(value == null ? "" : value.toString());
return this;
}
}
效果不是很好啊,,
有没有什么好的解决方案
------解决方案--------------------
可以试试根据内容的多少来适应,高度根据内容来变化
------解决方案--------------------