# Power table column widths resetting

**URL:** <https://forum.inductiveautomation.com/t/power-table-column-widths-resetting/89579>\
**Category:** Ignition\
**Tags:** vision, ignition81\
**Created:** [April 27, 2024, 3:32pm UTC](https://forum.inductiveautomation.com/t/power-table-column-widths-resetting/89579 "2024-04-27T15:32:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan.deason](https://avatars.discourse-cdn.com/v4/letter/d/a6a055/32.png) [@dan.deason](https://forum.inductiveautomation.com/u/dan.deason)\
**Post date:** [April 27, 2024, 3:32pm UTC](https://forum.inductiveautomation.com/t/power-table-column-widths-resetting/89579/1 "2024-04-27T15:32:33Z")

</div>

I've got a power table with a dataset consisting of [62R x 6C] and I'm showing 5 of the columns (by using the hide property on column 6)

It is similar to this post ( [Keep Power Table Column Width after table refresh](https://forum.inductiveautomation.com/t/keep-power-table-column-width-after-table-refresh/45957) ) but I really don't have a crazy number of rows or anything so I don't think it would be related to their "fix" in that one.

it doesn't matter if I manually adjust the column widths or if I programmatically change the column widths using this code:

```python
def FormatColumns(self):
	"""
	Arguments:
		self: A reference to the component instance this method is invoked on. This argument
		  is automatic and should not be specified when invoking this method.
	"""
	t = self.getTable()
	g = t.getGraphics()
	frc = g.getFontRenderContext()
	
	
	
	fm = t.getFontMetrics(t.getFont())
	c0 = fm.stringWidth(" __0000__")
	c1 = fm.stringWidth(" __active__")
	c3 = fm.stringWidth(" __00-00 00:00:00__")
	c4 = fm.stringWidth(" __00-00 00:00:00__")
	w = self.getWidth() - fm.stringWidth(" ____")
	c2 = w - c4 - c3 - c1 - c0
	
	print(c0, c1, c2, c3, c4, w)
	
	#print(dir(t))
	
	print(self.getBounds())
	
	
	print(fm.stringWidth("name"))
	
	
	self.setColumnWidth(0, c0)
	self.setColumnWidth(1, c1)
	self.setColumnWidth(2, c2)
	self.setColumnWidth(3, c3)
	self.setColumnWidth(4, c4)

```

Whenever the dataset updates, the columns revert back to auto-sized with all columns an equal 20% of the screen width. If I change the Auto-Resize mode to off, they revert back to all being a fixed width.

I tried re-running the column width auto-setting function on property change, but it flickers so that was a bust.

I'm not really sure what I should start monitoring or logging to determine the cause of the re-size.

It appears to be intermittent and i did not notice it doing it until today. I couldn't get it to NOT do it half an hour ago, and now it is back to not doing it.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [April 28, 2024, 1:27am UTC](https://forum.inductiveautomation.com/t/power-table-column-widths-resetting/89579/2 "2024-04-28T01:27:31Z")

</div>

I'm not sure what causes this. I ran into a problem similar to this with a popup table I was developing a little while back, and I fixed it by switching to a regular table. I was displaying zero to ten rows of data in the popup, so it couldn't have been related to the issue you linked to either.

Is there a reason that a power table is needed to display this data? If not, you could eliminate the potential for this problem by switching to a regular table and directly specifying the column widths in the regular table's column attributes data.

---

<div class="post-metadata">

**Author:** ![dan.deason](https://avatars.discourse-cdn.com/v4/letter/d/a6a055/32.png) [@dan.deason](https://forum.inductiveautomation.com/u/dan.deason)\
**Post date:** [April 29, 2024, 8:27pm UTC](https://forum.inductiveautomation.com/t/power-table-column-widths-resetting/89579/3 "2024-04-29T20:27:38Z")

</div>

The biggest thing is the word-wrap and auto-row height on the power table. I guess I can hunt down the swing docs and set the properties for the regular table but I would rather not have to.

---

<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:** [April 29, 2024, 9:53pm UTC](https://forum.inductiveautomation.com/t/power-table-column-widths-resetting/89579/4 "2024-04-29T21:53:17Z")

</div>

> [@dan.deason](#):
>
> I guess I can hunt down the swing docs and set the properties for the regular table but I would rather not have to.

Neither of those are an option with a regular JTable, so you're stuck with the power table. Under the hood it's a JideTable.

Consider pushing the whole problem at hand onto Jide's built in utility class designed for this purpose: [TableUtils](https://seadas.gsfc.nasa.gov/mvn-seadas/junk/javadoc/com/jidesoft/grid/TableUtils.html#autoResizeAllColumns(javax.swing.JTable)). You'll need to get a reference to the inner 'real' table component inside the VisionAdvancedTable 'wrapper', but I've had good luck with this utility.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [April 30, 2024, 1:06am UTC](https://forum.inductiveautomation.com/t/power-table-column-widths-resetting/89579/5 "2024-04-30T01:06:28Z")

</div>

If you are okay with the columns not being resizeable, a simple solution would be to set the column widths to fixed size when the table is painted using the power table's configureCell extension function.

**Example:**

```python
#def configureCell(self, value, [...], rowView, colView):
	
	# Only adjust the column sizes once per painting cycle by limiting the action to the first row
	if rowIndex == 0:
		# Create a list of desired column sizes
		customColumnWidths = [50, 50, 80, 40, 100]
		defaultColumnWidth = 100
		# Overflow protection, in case a column is added at some point
		if colIndex < len(customColumnWidths):
			# Set the columns to a fixed size as they are painted
			self.table.columnModel.getColumn(colIndex).minWidth = customColumnWidths[colIndex]
			self.table.columnModel.getColumn(colIndex).maxWidth = customColumnWidths[colIndex]
			self.table.columnModel.getColumn(colIndex).width = customColumnWidths[colIndex]
		else:
			# Set any overflow columns to a default width
			self.table.columnModel.getColumn(colIndex).minWidth = defaultColumnWidth
			self.table.columnModel.getColumn(colIndex).maxWidth = defaultColumnWidth
			self.table.columnModel.getColumn(colIndex).width = defaultColumnWidth

```
