Get table width

Is it possible to get a tables width? I want to make sure the element above it always has the same width.

Hi bellm,

Through scripting or not?

To get the width manually in the designer click on a table and then press Control-p.

To get the width in scripting use this:

table = event.source.parent.getComponent('Power Table')
print table.widthtable = event.source.parent.getComponent('Power Table')
print table.width


1 Like

what about for an individual column? is there a document or something that list all the attributes you can chose from?

To get the width for a single column, you need to first get the underlying JTable.
This code will display the width of all columns:

[code]t=event.source.parent.getComponent(‘Power Table’).getTable() # get underlying table
# get number of columns

for i in range©:
colName=t.getColumnName(i) # get column name
cellRect=t.getCellRect(0,i,True) # get rectangle from top cell in column
colWidth=cellRect.width # get width of the rectangle
print colName, colWidth # print it


The documentation for the underlying JTable can be found here.

1 Like

Sorry. Should explain a bit further…

getCellRect returns a Rectangle of a cell:

getCellRect(row, col, includeSpacing)

The rectangle it returns has four items in it: x, y, width, and height. These are the position and size of the rectangle.
Note: the position is relative to the table itself. For example, the cell at the upper left will always be at 0,0 (x and y, respectively).