# Table headers not centered

**URL:** <https://forum.inductiveautomation.com/t/table-headers-not-centered/19969>\
**Category:** Ignition\
**Tags:** ignition78\
**Created:** [October 3, 2018, 9:05pm UTC](https://forum.inductiveautomation.com/t/table-headers-not-centered/19969 "2018-10-03T21:05:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bellm](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bellm](https://forum.inductiveautomation.com/u/bellm)\
**Post date:** [October 3, 2018, 9:05pm UTC](https://forum.inductiveautomation.com/t/table-headers-not-centered/19969/1 "2018-10-03T21:05:21Z")

</div>

I was hoping somebody could help me with some formatting issues I am finding with a table I am using. I have table component that I would like the header to be centered and word wrapped. I added html to the header to center and break the two words into separate lines but the text doesn’t exactly center. it is especially noticeable when resizing the cell. Anybody have a suggestion as to what I can do to get it to center?

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/97e9a9ee8d6f4aa486d1564eb9641f8bba091333.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 3, 2018, 9:37pm UTC](https://forum.inductiveautomation.com/t/table-headers-not-centered/19969/2 "2018-10-03T21:37:49Z")

</div>

Hmmm. That space is reserved for a “sort” indicator arrow, if I recall correctly. You could dig around in Java Swing’s [JTable.setTableHeader()](https://docs.oracle.com/javase/8/docs/api/javax/swing/JTable.html#setTableHeader-javax.swing.table.JTableHeader-) method documentation to try to substitute one that centers the way you wish.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 4, 2018, 11:43am UTC](https://forum.inductiveautomation.com/t/table-headers-not-centered/19969/3 "2018-10-04T11:43:57Z")

</div>

To illustrate what Phil is talking about:

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/da996f7a57ff7b51910b891f46e1aaefc0f5872a.jpg)

---

<div class="post-metadata">

**Author:** ![bellm](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bellm](https://forum.inductiveautomation.com/u/bellm)\
**Post date:** [October 4, 2018, 12:32pm UTC](https://forum.inductiveautomation.com/t/table-headers-not-centered/19969/4 "2018-10-04T12:32:48Z")

</div>

Thank you for your replies, I guess I will just have to live with it since I do not have the expertise to mess with the java.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 4, 2018, 3:38pm UTC](https://forum.inductiveautomation.com/t/table-headers-not-centered/19969/5 "2018-10-04T15:38:47Z")

</div>

You’ll probably want this to fire automatically - probably on propertyChange of the `data` attribute, but this should get you started. `table.getColumnModel().getColumn(1)` sets the index of the column to modify (from 0, counting from left to right).

```auto
from javax.swing.table import TableCellRenderer

table = event.source.parent.getComponent('Table').getTable()

class NonSortableHeaderRenderer(TableCellRenderer):
	def getTableCellRendererComponent(self, table, value, selected, focused, row, col):
		renderer = table.getTableHeader().getDefaultRenderer()
		comp = renderer.getTableCellRendererComponent(table, value, selected, focused, row, col)
		comp.setIcon(None)
		return comp
		
table.getColumnModel().getColumn(1).setHeaderRenderer(NonSortableHeaderRenderer())

```

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/dab6da755fd3414dbd30dff23659692503eadbc8.png)

---

<div class="post-metadata">

**Author:** ![bellm](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bellm](https://forum.inductiveautomation.com/u/bellm)\
**Post date:** [October 4, 2018, 4:18pm UTC](https://forum.inductiveautomation.com/t/table-headers-not-centered/19969/6 "2018-10-04T16:18:59Z")

</div>

Thank you very much. I will give this a shot.

---

<div class="post-metadata">

**Author:** ![bellm](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bellm](https://forum.inductiveautomation.com/u/bellm)\
**Post date:** [November 6, 2018, 7:52pm UTC](https://forum.inductiveautomation.com/t/table-headers-not-centered/19969/7 "2018-11-06T19:52:58Z")

</div>

To kind of follow up what you had posted here about the centering, could I do something similar to modify the header’s color and line type? I would like it to have a plain line instead of what appears to be an etched or beveled line.

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/0eeac11310681f2b8c3f4aecee13fb73929d6312.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 6, 2018, 7:56pm UTC](https://forum.inductiveautomation.com/t/table-headers-not-centered/19969/8 "2018-11-06T19:56:58Z")

</div>

> [@paul-griffith](#):
>
> comp = renderer.getTableCellRendererComponent(table, value, selected, focused, row, col)  
> comp.setIcon(None)  
> return comp

Yes, you can - you would need to modify the `comp` returned in the middle of the script. For what you can do, unfortunately there's no reference more useful than the Javadocs for JComponent/JLabel:  
[https://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html](https://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html)  
[https://docs.oracle.com/javase/7/docs/api/javax/swing/JLabel.html](https://docs.oracle.com/javase/7/docs/api/javax/swing/JLabel.html)

---

<div class="post-metadata">

**Author:** ![bellm](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bellm](https://forum.inductiveautomation.com/u/bellm)\
**Post date:** [November 6, 2018, 7:59pm UTC](https://forum.inductiveautomation.com/t/table-headers-not-centered/19969/9 "2018-11-06T19:59:26Z")

</div>

Thank you very much.
