模仿JTable中行呈现的默认行为
在Java 7应用程序中,我使用带有两列的Swing JTable
.左列使用DefaultTableCellRenderer
,其中setHorizontalAlignment()
设置为居中,而右列不使用特定渲染器.
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.
使用DefaultTableCellRenderer
时,是否有任何(简便)的方法来模仿行渲染的默认行为(即,交替显示颜色和突出显示的行)?
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:我正在使用L& F.
PS: I am using the Substance L&F.
是否有任何(简便)的方法来模仿该行的默认行为 渲染时(即交替的颜色和突出显示的行) 使用DefaultTableCellRenderer?
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
具有自己的Renderer
,您应在之前添加Substance
来更改XxxXxxRenderer
,例如
SubstanceDefaultTableCellRenderer
而不是DefaultTableCellRenderer
,对于JComboBox
,JList
,JTree
或JTableHeader
Substance
has own Renderer
s, you should change XxxXxxRenderer
by add Substance
before, e.g.
SubstanceDefaultTableCellRenderer
instead of DefaultTableCellRenderer
, the same for JComboBox
, JList
, JTree
or JTableHeader