简体   繁体   English

JTable,使单元格文本多行

[英]JTable, make cell text multiline

I have a JTable where each cell occupy the same amount of space, but somethimes happen that text doesn't fit well inside cell, so i can't read entire content. 我有一个JTable,其中每个单元格都占据相同的空间量,但是发生了一些变故,文本不能很好地适合单元格内部,因此我无法读取全部内容。 There's a way to adapt each table row height for show correctly all its content? 有一种方法可以调整每个表格行的高度,以正确显示其所有内容? So each table row could have different height, and the maximum heigth o row is the minimum height to contain thew most long text 因此每个表格行可以具有不同的高度,最大行o是包含最长文本的最小高度

You can set the row height individually. 您可以单独设置行高。 When any value is changed, call this code: 更改任何值后,请调用以下代码:

int height = table.getRowHeight(row);
int newHeight  = table.prepareRenderer(table.getCellRenderer(row, column), row, column).getPreferredSize().height;
if (newHeight > height) {
    height = newHeight;
}
table.setRowHeight(row, rowHeight);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM