# Get table width

**URL:** <https://forum.inductiveautomation.com/t/get-table-width/10097>\
**Category:** Ignition\
**Created:** [June 6, 2015, 5:31pm UTC](https://forum.inductiveautomation.com/t/get-table-width/10097 "2015-06-06T17:31:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bellm](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bellm](https://forum.inductiveautomation.com/u/bellm)\
**Post date:** [June 6, 2015, 5:31pm UTC](https://forum.inductiveautomation.com/t/get-table-width/10097/1 "2015-06-06T17:31:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [June 7, 2015, 4:03pm UTC](https://forum.inductiveautomation.com/t/get-table-width/10097/2 "2015-06-07T16:03:09Z")

</div>

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:

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

Best,

---

<div class="post-metadata">

**Author:** ![bellm](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bellm](https://forum.inductiveautomation.com/u/bellm)\
**Post date:** [June 8, 2015, 3:34pm UTC](https://forum.inductiveautomation.com/t/get-table-width/10097/3 "2015-06-08T15:34:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 8, 2015, 7:09pm UTC](https://forum.inductiveautomation.com/t/get-table-width/10097/4 "2015-06-08T19:09:51Z")

</div>

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  
c=t.getColumnCount()

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

[/code]

The documentation for the underlying JTable can be found [here](http://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html).

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 8, 2015, 7:16pm UTC](https://forum.inductiveautomation.com/t/get-table-width/10097/5 "2015-06-08T19:16:29Z")

</div>

Sorry. Should explain a bit further…

getCellRect returns a Rectangle of a cell:

```auto
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).
