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

Ranorex Studio, Spy, Recorder, and Driver.
nandeesh
Posts: 14
Joined: Tue Jun 12, 2012 12:07 pm

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

Post by nandeesh » Tue Feb 26, 2013 1:54 pm

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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

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

Post by Support Team » Wed Feb 27, 2013 5:57 pm

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)