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