Page 1 of 1

How to get the javax.swing.JTable Cells text width

Posted: Tue Feb 26, 2013 1:54 pm
by nandeesh
Hi,

Is there any way to get the javax.swing.JTable cells (content) text width provided cells text font is
Font("Arial", 16).

I am trying get the maximum width Ranorex.Table.Column[].Cell[].Text.

Thanks.

Re: How to get the javax.swing.JTable Cells text width

Posted: Wed Feb 27, 2013 5:57 pm
by Support Team
Hello,

You could use the 'Length' property of the text to get the number of characters.
If you want to get the maximum text width, you could iterate over all cells and compare the value.
Please take a look at the code snippet below:
int maxLength = 0;
IList<Cell> cells = Host.Local.Find<Cell>("/form[@title='Java Test']//table[@name='jTable1']/row/cell");

foreach (Cell cell in cells)
{
	Report.Info("Cell: " + cell.Text + " Width: " + cell.Text.Length);
	if (cell.Text.Length>maxLength)
		maxLength = cell.Text.Length;
}
Report.Info("Length: " + maxLength);
You could access the font and size of the table by using the following code:
jTable1.Element.GetAttributeValueText("Font.Name")
jTable1.Element.GetAttributeValueText("Font.Size")
Regards,
Markus (T)