Power Table Fixed Relative Column Size

Hello,

I have a problem with my power table not always applying the width sizing for my columns.

I looked at this post but that is really the opposite of what my problem is. I do have the Auto Row Height, Columns Resizable set and the Auto-Resize Mode is set to Next Column.

I have attempted various settings of the above settings and some made it worse and but none made it better.

I set the widths by running the window in the developer, adjusting the column widths and then stopping the window and saving things. If there is a better way to do this I’d like to know, and know where it is documented (so I know what I missed)!

The following is the contents of the Column Sizing property:

6	1268	Feature #	0	2147483647	15	100	100	Side	1	2147483647	15	100	100	Robot Type	2	2147483647	15	100	100	Tool Type	3	2147483647	15	300	300	Station	4	2147483647	15	500	500	Modified?	5	2147483647	15	150	150			1	7	1	Feature #	Side	Robot Type	Tool Type	Station	Modified?

Which doesn’t really mean much to me.

What is really weird is that it sometimes formats the table correctly if I leave the screen and go back to it.

Thanks for any help.

Bill

Not sure what your ideal setup is, but you might try this code. It will autosize all the columns based on the width of the contents. It works very well for me on wide tables.

		from com.jidesoft.grid import TableUtils
		from javax.swing import JTable
		table = system.gui.getParentWindow(event).getComponentForPath('Root Container.Table3').getTable()
		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
		TableUtils.autoResizeAllColumns(table)
1 Like

Thank you for the suggestion. I think because of the fact that I override the renderer and replace the contents a bit I might be confusing things…

Example: I have a Tool column that contains “A,B,C” and what gets displayed is “Tool 1, Tool 2, Tool 3” this column can dynamically take multiple rows when needed the replacements are derived from another table, I have another column that just displays the refresh icon which is using a custom renderer. Then there is the column that has “N” or “S” which displays as “North” or “South”. And of course my Type column that has “2”, “7”, or “9” which displays as “M2000”, “M710”, or “M900” from another table.

The Tool and Type columns have dynamic drop downs getting data from another table, and the tool drop down allows multiple selections (which I have an outstanding question about) Most of the code is in the other forum post.

So, does the auto width sizing go off of the shorter string or the string returned by configureCell? Also, what does it do when configureCell returns a different renderer like the refresh column?

Thanks again,
Bill

I didn’t see the link in your original post. I gave some code you already had access to. Try the code in the propertyChange event of the table inside an if statement

if event.source.propertyName == 'data':
      from com.jidesoft.grid import TableUtils
      from javax.swing import JTable
      table = system.gui.getParentWindow(event).getComponentForPath('RootContainer.Table3').getTable()
      table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
      TableUtils.autoResizeAllColumns(table)      
1 Like

That doesn’t do what I want…

The table does not stretch to the full width of the power table, and the Tools field does not get big enough…

BTW: did you know that you do not have to do the getComponentForPath if you are doing the code in the propertyChange for the Power Table? event.source IS the component. Unfortunately even though the dir(event.source) indicates that getTable() is there, it doesn’t work. I used event.source.table and everything works.

elif event.propertyName == "data":
	from com.jidesoft.grid import TableUtils
	from javax.swing import JTable
	
#	table = event.source.getTable()
	table = event.source.table
	table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
	TableUtils.autoResizeAllColumns(table, True)
	TableUtils.autoResizeAllRows(table)

But like I said, it doesn’t display the way I wanted it to AND doesn’t change the fact that I set sizes then they got changed!

Thank you,
Bill

1 Like

You should be able to adjust the columns widths then save it like you said you did and it stay that way, but you would have to set the auto resize mode to off wouldn’t you? You could try an initialize extension function like below. Again auto resize set to off.

       tbl = self.parent
	
	tbl.setColumnWidth(0,105)
	tbl.setColumnWidth(1,95)
	tbl.setColumnWidth(2,335)
	tbl.setColumnWidth(3,60)
	tbl.setColumnWidth(4,60)
	tbl.setColumnWidth(5,60)
	tbl.setColumnWidth(6,60)
	tbl.setColumnWidth(7,60)
	tbl.setColumnWidth(8,60)
	tbl.setColumnWidth(9,95)

I know this post is older, but where are you inserting this script?

This code goes in scripting for the table. I presently have it being called in the initialize method and on change of “data”…

if event.propertyName in ( "editor", "componentRunning" ):
	if event.newValue:
		self.setupColumns()

elif event.propertyName == "data":
	if event.newValue != None:
		self.setupColumns()

The following is a major hack and isn’t as dynamic as I had hoped. I had to adjust to allow for the width of the scrollbar on the right side.

With a Custom Method defined:

def setupColumns(self):
	from com.jidesoft.grid import TableUtils
	from javax.swing import JTable
	
	rootContainer = self.parent.parent
	
	data = self.data
	width = self.getWidth()
	pnWidth = int(width * 0.25)
	dsWidth = int(width * 0.5675)
	otWidth = int(width * 0.145)
		
	headers = system.dataset.getColumnHeaders(data)
	colSizes = [ ]
	for header in headers:
		if header == "PartNumber":
			colSizes.append(pnWidth)
		elif header == "Description":
			colSizes.append(dsWidth)
		elif header in ( "Id", "CNCProgram", "InfeedPickGripDistance", "InfeedTiltAngle", "GripperPadSizeT2A", "GripperPadT2B", "WrenchPadSize", "DropDistance", "GripperSizeT1", "CNCGripDistance", "Width", "GripperSizeT2B", "GripperOffsetT2B" ):
			pass
		else:
			colSizes.append(otWidth)
	
	logger.info("ColSizes %s" % (str(colSizes)))
	
	table = self.table
	table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
	TableUtils.autoResizeAllColumns(table, colSizes, colSizes, True, True, False, True )
	TableUtils.autoResizeAllRows(table)

For this particular table, I’m only displaying 3 columns and I want the description to take up most of the screen real estate.

I call this from within the initialize method and the propertyChange method. This works, but not as well as if the darn thing saved my settings the way it used to.

I get flashes of the table with all the columns scrunched to the left side, then it will reformat to the way I want it.

I REALLY wish that the thing could do this automatically based on given percentages that you lay out in the designer.

Anyway, hope this helps somebody.

Bill

2 Likes

Copy - Paste - Change the name of the table & BAM!

(Note - Auto resize mode needed to be set to OFF)

NICE! TYVM.

1 Like