English 中文(简体)
如何根据在囚室输入的案文内容,提高囚室里的一行的高度
原标题:How to increase the height of a row in jtable depending on the text content entered in its cell

我有一个可以调和的支架。 当单元由用户撰写时,如果输入文本更适合电池大小,那么表格中的行顶必须增加,以适应用户输入的新案文。 各位能否告诉我,如何根据所签案文的行文提高行的高度。

Can anyone help me in this? I have tried to add JTextArea into a row, but this is not working.

问题回答

您将需要计算新文本所需的高度。 视您在囚室使用的病因而定,您可使用例如JTextArea.getLineCount(,以找出案文中有多少条线。

Then you need to retrieve the height of the font used by the renderer and calculate the needed height out of that.

Once you have that number, use JTable.setRowHeight(int, int) to change the height for the specific row.

与此类似:

Component c = renderer.getTableCellRendererComponent(theTable, theTable.getValueAt(row, col), false, false, row, col);
Font f = c.getFont();
FontMetrics fm = c.getFontMetrics(f);

// this cast depends on the way your renderer is implemented !!!!
int lineCount = ((JTextArea)c).getLineCount();

int fheight = fm.getHeight();
int rowHeight = lineCount * fheight;


theTable.setRowHeight(row, rowHeight); //NOTE: rows and columns are zero-indexed

单价部分的加权依据的是配量,而不是该行所用电离器的优厚度:

www.exampledepot.com/egs/javax.swing.table/RowHels.html





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签