# Power Table Auto Column Size

**URL:** <https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151>\
**Category:** Ignition\
**Tags:** ignition78, scripting\
**Created:** [August 24, 2017, 12:57am UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151 "2017-08-24T00:57:14Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![robert1](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@robert1](https://forum.inductiveautomation.com/u/robert1)\
**Post date:** [August 24, 2017, 12:57am UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/1 "2017-08-24T00:57:14Z")

</div>

Hello-

Is it possible to “auto size all columns” of a power table via scripting? I can right click on a table and click this option in a popup, but using powerTable.autoResizeMode = 4 or changing auto resize mode to “all columns” does not work for me because I have a screen with a lot of small power tables with pretty dynamic data where the column widths need to change with updated data. So I would like to be able to do the same action that the popup click does, but do it every time I query new data. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 25, 2017, 12:02am UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/2 "2017-08-25T00:02:09Z")

</div>

```python
from com.jidesoft.grid import TableUtils
from javax.swing import JTable
table = event.source.parent.getComponent('Power Table').getTable()

table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
TableUtils.autoResizeAllColumns(table)

```

First, third, and last lines are most important.

---

<div class="post-metadata">

**Author:** ![robert1](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@robert1](https://forum.inductiveautomation.com/u/robert1)\
**Post date:** [August 25, 2017, 5:25pm UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/3 "2017-08-25T17:25:50Z")

</div>

That worked perfect, thank you very much.

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [April 5, 2018, 3:11pm UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/4 "2018-04-05T15:11:13Z")

</div>

This is great but one followup question,  
I have some tables that have 100 columns and I cant fit them in one page so I have to Turn off the Auto resize mode and that adds a horizontal scroll bar to my table that way all the columns can fit and look good. is he following enough to make sure when the window opens all the column auto resize while the auto resize mode stays off?

```auto
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
TableUtils.autoResizeAllColumns(table)

```

Or should I do the following

```auto
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS)
TableUtils.autoResizeAllColumns(table)
system.gui.getParentWindow(event).getComponentForPath('Root Container.Table').autoResizeMode = 0

```

Woulnt the second one basically auto resize everything and then at the end it turns the auto resize mode to off and give me the look I want or are there two basically do the same thing?

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [April 5, 2018, 4:53pm UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/5 "2018-04-05T16:53:32Z")

</div>

I’m confused… I tested different versions of my script on a buttons actionPerformed event and it worked like a charm, anytime I change the column sized and click the button all the columns resize how they should BUT if I use the same script on visionWIndowOpened event handler of that Window it doesn’t work… Am I doing something wrong?  
I tried different ways of this script that’s why you see the hashtags

```auto
from com.jidesoft.grid import TableUtils
from javax.swing import JTable
table = system.gui.getParentWindow(event).getComponentForPath('Root Container.Table').getTable()
#table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS)
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
TableUtils.autoResizeAllColumns(table)
#system.gui.getParentWindow(event).getComponentForPath('Root Container.Table').autoResizeMode = 0

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 5, 2018, 5:05pm UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/6 "2018-04-05T17:05:22Z")

</div>

The visionWindowOpened event happens really early – components aren’t setup yet. You probably want the internalFrameActivated event.

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [April 5, 2018, 5:08pm UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/7 "2018-04-05T17:08:04Z")

</div>

@pturmel  
That crossed my mind so I tested it on internalFrameActivated/Opened and both visionWindowOpened/Closed and still nothing… 😵

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 5, 2018, 5:09pm UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/8 "2018-04-05T17:09:54Z")

</div>

Oh, you have to wait for the data to show up, sorry. Try a propertyChange event looking at the ‘data’ property of your table.

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [April 5, 2018, 5:27pm UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/9 "2018-04-05T17:27:02Z")

</div>

This script on the propertyChange even of the table worked fine.  
`if event.propertyName == "data"`  
When the window opens for a sec you see the one column not being resized and then when the tables propertyChange applies the column is resized…

I could do the same thing on the propertyChange event handler of the windows as well correct? I just have can’t use event and have to point to the table right?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 5, 2018, 5:29pm UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/10 "2018-04-05T17:29:03Z")

</div>

A propertyChange event must be on the component that has the property you wish to monitor.

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [April 5, 2018, 6:08pm UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/11 "2018-04-05T18:08:21Z")

</div>

Thanks, the propertyChange of the table method seems to work fine so I’ll stick with that.

---

<div class="post-metadata">

**Author:** ![Mitchb741](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@Mitchb741](https://forum.inductiveautomation.com/u/Mitchb741)\
**Post date:** [May 19, 2018, 4:14pm UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/12 "2018-05-19T16:14:07Z")

</div>

Curious what I may be missing. I had the same issue with length of a table so I tried your code and couldn’t get it to work. Its on a property change of a text box so when the user selects the text box which in turn changes the query the event occurs. Though when I try the original code in this thread that works fine yet like the problem you had it was scrunched

from com.jidesoft.grid import TableUtils  
from javax.swing import JTable  
table = system.gui.getParentWindow(event).getComponentForPath(‘Root Container.Power Table’).getTable()

table.setAutoResizeMode(JTable.AUTO\_RESIZE\_OFF)  
TableUtils.autoResizeAllColumns(table)

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [January 30, 2019, 11:07pm UTC](https://forum.inductiveautomation.com/t/power-table-auto-column-size/15151/13 "2019-01-30T23:07:29Z")

</div>

Where are you using this code in?
