Mimic default behaviour of row rendering in a JTable

我的未来我决定 提交于 2019-12-24 13:40:26

问题


In my Java 7 application I use a Swing JTable with two columns. The left column uses a DefaultTableCellRenderer where the setHorizontalAlignment() is set to centered, whereas the right column uses no specific renderer.

That right column shows each table row in alternating colors by default, which is not the case on the left column with the renderer used. Moreover, when I hover with the mouse over the rows on the right column, then the row under the mouse curser is highlighted when focused, which also isn't the case with the left column.

Is there any (easy) way of mimic the default behaviour of the row rendering (i.e. the alternating colors and the highlighted row) when using a DefaultTableCellRenderer?

PS: I am using the Substance L&F.


回答1:


Is there any (easy) way of mimic the default behaviour of the row rendering (i.e. the alternating colors and the highlighted row) when using a DefaultTableCellRenderer?

Substance has own Renderers, you should change XxxXxxRenderer by add Substance before, e.g. SubstanceDefaultTableCellRenderer instead of DefaultTableCellRenderer, the same for JComboBox, JList, JTree or JTableHeader



来源:https://stackoverflow.com/questions/19738035/mimic-default-behaviour-of-row-rendering-in-a-jtable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!