Power table column widths resetting

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 ) 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:

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.

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.

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.

1 Like

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. 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.

1 Like

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:

#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