# How to get Table Column Width?

**URL:** <https://forum.inductiveautomation.com/t/how-to-get-table-column-width/5209>\
**Category:** Ignition\
**Created:** [September 27, 2012, 6:26pm UTC](https://forum.inductiveautomation.com/t/how-to-get-table-column-width/5209 "2012-09-27T18:26:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![skallepalli](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@skallepalli](https://forum.inductiveautomation.com/u/skallepalli)\
**Post date:** [September 27, 2012, 6:26pm UTC](https://forum.inductiveautomation.com/t/how-to-get-table-column-width/5209/1 "2012-09-27T18:26:19Z")

</div>

Dear Inductive Team,

We had a requirement where we need to get Table Column width in Event Handler. We mean, Is there any function similar to setColumnWidth() function where we can get Column width on Runtime (In Launched Project) ?

We had a look at columnAttributesData for table component. However, values in this dataset are not changing runtime.

---

<div class="post-metadata">

**Author:** ![Michael.Stofan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.stofan/32/3342_2.png) [@Michael.Stofan](https://forum.inductiveautomation.com/u/Michael.Stofan)\
**Post date:** [September 27, 2012, 9:12pm UTC](https://forum.inductiveautomation.com/t/how-to-get-table-column-width/5209/2 "2012-09-27T21:12:07Z")

</div>

You can use this:

```auto
table = event.source.parent.getComponent("Table")

print table.table.columnModel.getColumn(2).getWidth()
```

Where ‘2’ is the column index, meaning the third column in your table. Hope this helps, take care.

---

<div class="post-metadata">

**Author:** ![skallepalli](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@skallepalli](https://forum.inductiveautomation.com/u/skallepalli)\
**Post date:** [September 28, 2012, 3:46am UTC](https://forum.inductiveautomation.com/t/how-to-get-table-column-width/5209/3 "2012-09-28T03:46:24Z")

</div>

Thank you Michael. It works perfect.

One more question. Is there any event that will fire when we change Column width in Launched Project ? We tried with PropertyChange, MousePressed Events. However these events are not firing on Column (in Column Header) width change.

---

<div class="post-metadata">

**Author:** ![Michael.Stofan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.stofan/32/3342_2.png) [@Michael.Stofan](https://forum.inductiveautomation.com/u/Michael.Stofan)\
**Post date:** [September 28, 2012, 5:19pm UTC](https://forum.inductiveautomation.com/t/how-to-get-table-column-width/5209/4 "2012-09-28T17:19:12Z")

</div>

There is a way to do it, but it is a little tricky. There is nothing listening to the column width event by default, but you can implement your own propertyChangeListener. You’d want to put something like this on the visionWindowOpened event handler of a window:

```auto
table = event.source.rootContainer.getComponent("Table")
from java.beans import PropertyChangeListener
class MyListener(PropertyChangeListener):
	def propertyChange(self, event):
		if event.propertyName == "width":
			print event.newValue
			
table.table.columnModel.getColumn(0).addPropertyChangeListener(MyListener())
```

The ‘print event.newValue’ is where the new value of the column width gets printed, and you’ll notice you have to implement the listener on every column you’re interested in. In this case, I’ve hard-coded column 0 (the last line). Hope this is helpful, talk to you later.

---

<div class="post-metadata">

**Author:** ![skallepalli](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@skallepalli](https://forum.inductiveautomation.com/u/skallepalli)\
**Post date:** [October 1, 2012, 11:09am UTC](https://forum.inductiveautomation.com/t/how-to-get-table-column-width/5209/5 "2012-10-01T11:09:39Z")

</div>

Michael,

It worked perfect. Here we go with one more issue. We set autoResizeMode to off for Table component (Ex: tblData) for better column data visibility which shows Horizontal scroll bar. Why we need to do all this (fetching column width on runtime, event for triggering the change etc.) ? We are trying to put another Table component (Ex: tblSearch) exactly below the tblData for searching. We need to have same no. of columns in tblSearch as in tblData and same columns position (with same width as well) so that they can search it easily.

How we can get Scroll Position ? Is there better way for achieving above requirement ?

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [October 1, 2012, 9:47pm UTC](https://forum.inductiveautomation.com/t/how-to-get-table-column-width/5209/6 "2012-10-01T21:47:13Z")

</div>

You can get an instance of the horizontal scroll bar of a component by calling getHorizontalScrollBar(), then you can use getValue() and setValue() to match up the scrollbars of the two tables:

`comp = event.source.parent.getComponent("Table")
comp2 = event.source.parent.getComponent("Table 1")
value = comp.getHorizontalScrollBar().getValue()
comp2.getHorizontalScrollBar().setValue(value)`

The value that is returned from getValue is an integer, which is the number of pixels that the scrollbar has been offset from the left arrow.

---

<div class="post-metadata">

**Author:** ![skallepalli](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@skallepalli](https://forum.inductiveautomation.com/u/skallepalli)\
**Post date:** [October 2, 2012, 12:47pm UTC](https://forum.inductiveautomation.com/t/how-to-get-table-column-width/5209/7 "2012-10-02T12:47:45Z")

</div>

James and Michael,

Your code works perfect. Thank you for your quick responses.

We are glad to work on Ignition with your support.
