Power Table limit column size

Vision v8.0.15 - Power Table

I have this code on the Property Change event for the power table:

from com.jidesoft.grid import TableUtils
from javax.swing import JTable
	
if event.propertyName == "data":
	table = event.source.getTable()
	table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS)
	TableUtils.autoResizeAllColumns(table)
	table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
	TableUtils.autoResizeAllColumns(table)

For the most part this does what I need. However, is there a way I can limit a column size? Or better yet, on large columns any way to do word wrap and make that row larger?

I looked at Java’s JTable methods and nothing jumped out at me to accomplish what you are asking with wrapping. For max size you would probably have to loop through all of the columns using getColumn() determine if it is over the max width, then alter it if true with setPreferredWidth() method.

colCount = table.getColumnCount()
for i in range(colCount):
    if table.getColumnModel().getColumn(i).getPreferredWidth() > 150:
        table.getColumnModel().getColumn(i).setPreferredWidth(150)
1 Like

Thanks, all I really needed is set a max, so,

table.getColumnModel().getColumn(5).setPreferredWidth(550)

works just fine for me regardless of what is in the cell.

2 Likes