Power Table Column Sizing Not Sticking on Version 8

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.

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

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

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?

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

Yes, here are all my settings

image

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

	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.

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.

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

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

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

How about this:

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

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

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.

1 Like

This works for you? I get

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

	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 -

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)

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.

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.

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