# Power Table Column Sizing Not Sticking on Version 8

**URL:** <https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844>\
**Category:** Ignition\
**Tags:** ignition80, vision\
**Created:** [February 2, 2020, 12:00am UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844 "2020-02-02T00:00:47Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![BillS](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@BillS](https://forum.inductiveautomation.com/u/BillS)\
**Post date:** [February 2, 2020, 12:00am UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/1 "2020-02-02T00:00:47Z")

</div>

Hello,

On version 7.X I would run the window in the editor adjust the columns then stop the editor and save the project. That would usually work to "lock" the column sizes the way I wanted. I really didn't change any of the column sizing flags. Sometimes the column sizes would not be what I wanted, but usually they would be.

That trick does not seem to be working in version 8.x.

I get the feeling that I've been doing it wrong and am looking for the correct way to set column sizes on the power table component.

Thank you,  
Bill S.

---

<div class="post-metadata">

**Author:** ![BishopTroyJ](https://avatars.discourse-cdn.com/v4/letter/b/50afbb/32.png) [@BishopTroyJ](https://forum.inductiveautomation.com/u/BishopTroyJ)\
**Post date:** [May 13, 2021, 8:34pm UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/2 "2021-05-13T20:34:59Z")

</div>

I am having this same issue. Is there a resolution to this? Cannot seem to get column sizing to stick in power table…

Troy B

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 23, 2022, 6:41pm UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/3 "2022-05-23T18:41:30Z")

</div>

Currently having an issue with setting column sizes again - I think last time I had just set them via script console and `table.setColumnWidth(0,100)` etc, and then not touching the table in designer.

Recently made a change on that window, something in the table changed, and the columns are all messed up now. I am trying to figure out the “right” way to do this.

I have this

```auto
self.setColumnWidth(0, 100)
self.setColumnWidth(1, 120)
self.setColumnWidth(2, 440)

```

under my power table initialize extension function but it doe not work.

I could manually set them again via script console but the next time something on the table needs to change it will probably get reset again.

What is the “right” way to manually set column width sizes on a power table?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [May 23, 2022, 6:47pm UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/4 "2022-05-23T18:47:14Z")

</div>

Do you have the `Auto-Resize Mode` set to Off?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 23, 2022, 7:03pm UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/5 "2022-05-23T19:03:45Z")

</div>

Yes, here are all my settings

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/c/0c611e824964c6e8d81c5a611ddcee60dcd05a71.png)

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [May 23, 2022, 7:15pm UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/6 "2022-05-23T19:15:08Z")

</div>

try putting the column size script into a function and call it with `system.util.invokeLater()`

My favorite column sizing code is to auto size the columns based on the text in the columns

```auto
	def resize():
		#This code resizes columns to fit the component window
		from com.jidesoft.grid import TableUtils
		from javax.swing import JTable
		table = self.getTable()
		table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS)
		TableUtils.autoResizeAllColumns(table)
	system.util.invokeLater(resize)	

```

Using `JTable.AUTO_RESIZE_ALL_COLUMNS` will resize all columns according to text and makes sure it fits the component window. Using `JTable.AUTO_RESIZE_OFF` will do the same except it will add a horizontal scroll bar while making all text visible in each cell.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 23, 2022, 7:30pm UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/7 "2022-05-23T19:30:08Z")

</div>

> [@dkhayes117](#):
>
> ```python
> def resize():
> #This code resizes columns to fit the component window
> from com.jidesoft.grid import TableUtils
> from javax.swing import JTable
> table = self.getTable()
> table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS)
> TableUtils.autoResizeAllColumns(table)
> system.util.invokeLater(resize)	
> 
> ```

This does actually seem to at least get called from inside the Initialize extension function though the column sizing doesn't exactly meet my needs.

Any reason you can see why my function on the intiailize function doesn't work ? It doesn't seem to run - the columns remain all mushed up.

```python
def setColSize():
	self.setColumnWidth(0, 100)
	self.setColumnWidth(1, 120)
	self.setColumnWidth(2, 440)
system.util.invokeLater(setColSize)

```

Edit: I just put this in a property change event for now and it works fine, I just think its not how I'd like to set up my table column properties

```python
if event.propertyName =='data':
    event.source.setColumnWidth(0, 100)
    event.source.setColumnWidth(1, 120)
    event.source.setColumnWidth(2, 440)

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 23, 2022, 7:47pm UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/8 "2022-05-23T19:47:01Z")

</div>

> [@bkarabinchak.psi](#):
>
> Any reason you can see why my function on the intiailize function doesn’t work ?

Perhaps `self` isn't the reference you think it is?

How about this:

```python
def setColSize():
   table = self.getTable()
   table.setColumnWidth(0,100)
   table.setColumnWidth(1,120)
   table.setColumnWidth(2,440)
system.util.invokeLater(setColSize)

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [May 23, 2022, 7:58pm UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/9 "2022-05-23T19:58:21Z")

</div>

You shouldn't need to `getTable()`. I have some working scripts that do not use this.

> [@bkarabinchak.psi](#):
>
> Any reason you can see why my function on the intiailize function doesn’t work

How are you testing the `initialize` function? You have to close and commit the window then re-open the window in the designer for it to run again. I've found it better to test in the client when dealing with this function just to be sure.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 23, 2022, 8:29pm UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/10 "2022-05-23T20:29:39Z")

</div>

This works for you? I get

```auto
Traceback (most recent call last):
  File "<extension-method initialize>", line 12, in setColSize
AttributeError: 'com.inductiveautomation.factorypmi.application.com' object has no attribute 'setColumnWidth'

```

from

```auto
	def setColSize():
		table = self.getTable()
		table.setColumnWidth(0, 100) # Line 12
		table.setColumnWidth(1, 120)
		table.setColumnWidth(2, 440)
	system.util.invokeLater(setColSize)

```

@dkhayes117 I am testing in client. I purposefully have the columns the wrong size in designer so that I am making sure it runs correctly on a client.

I have been messing with it in script console as well and don’t `getTable` to do this -

```auto
win = system.gui.getWindow("Pop_HelpDesk")
rc = win.getRootContainer()

chatTable = rc.getComponent("PTable_Chat")
chatTable.setColumnWidth(0,100)
chatTable.setColumnWidth(1, 100)
chatTable.setColumnWidth(2, 100)

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [May 23, 2022, 8:41pm UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/11 "2022-05-23T20:41:26Z")

</div>

Hmm, where I have used `setColumnWidth()`, I’m calling it via a data propertyChange event. I still think that it should work from `initialize()` with invokeLater.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 24, 2022, 12:19pm UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/12 "2022-05-24T12:19:11Z")

</div>

Yes that is how I have it going now too, but I feel like the initialize extension function is the appropriate place it should be. I’ve tried it many times so far - setting the columns to the wrong width, and then opening it in the client, and it’s obviously not doing anything unfortunately. So I will leave it in the property change event for now.

---

<div class="post-metadata">

**Author:** ![Bastian\_Ignacio](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bastian_ignacio/32/43245_2.png) [@Bastian\_Ignacio](https://forum.inductiveautomation.com/u/Bastian_Ignacio)\
**Post date:** [May 8, 2023, 11:12pm UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/13 "2023-05-08T23:12:44Z")

</div>

en configureheaderstyle utilice esto:

```
table = self.getTable()

table.getTableHeader().getColumnModel().getColumn(4).setMaxWidth(150)
table.getTableHeader().getColumnModel().getColumn(4).setMinWidth(150)
table.getTableHeader().getColumnModel().getColumn(5).setMaxWidth(100)
table.getTableHeader().getColumnModel().getColumn(5).setMinWidth(100)
table.getTableHeader().getColumnModel().getColumn(6).setMaxWidth(100)
table.getTableHeader().getColumnModel().getColumn(6).setMinWidth(100)
table.getTableHeader().getColumnModel().getColumn(7).setMaxWidth(100)
table.getTableHeader().getColumnModel().getColumn(7).setMinWidth(100)
table.getTableHeader().getColumnModel().getColumn(8).setMaxWidth(100)
table.getTableHeader().getColumnModel().getColumn(8).setMinWidth(100)
table.getTableHeader().getColumnModel().getColumn(9).setMaxWidth(120)
table.getTableHeader().getColumnModel().getColumn(9).setMinWidth(120)

```

y funciona bien, bloqueo el ancho máximo mínimo

---

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [May 1, 2024, 5:46pm UTC](https://forum.inductiveautomation.com/t/power-table-column-sizing-not-sticking-on-version-8/31844/14 "2024-05-01T17:46:01Z")

</div>

The only way it did work from initialize is by adding some value to invokelater delay, I added 100 ms, it works okay
