0

I need to test that the color of java table row has changed to some specific value. But till now I see no solutions of getting this property.

Let's assume that jTableObj is OR or DP representation of JavaTable object. So the next code works fine:

jTableObj.GetCellData(0,1)    'returns cell data e.g.: <html>Blah-blah...

How can I get color of row/cell?

2 Answers 2

1

The next code solves the problem:

Set cellRender = jTableObj.Object.getCellRenderer(0,1)

' background color '
cellRender.getBackground().toString()
    ' returns: "javax.swing.plaf.ColorUIResource[r=255,g=255,b=255]" '

' font color '
cellRender.getForeground().toString()
    ' returns: "java.awt.Color[r=255,g=255,b=180]" '

' font name, style, size '
cellRender.getFont().toString()
    ' returns: "java.awt.Font[family=Tahoma,name=Tahoma,style=italic,size=11]" '
0

The above solution lacks a step. After:

Set cellRender = jTableObj.Object.getCellRenderer(0,1)

There must come:

component = jTableObj.Object.prepareRenderer(cellRender, 0, 1)

And only then:

' background color '
component.getBackground().toString()
' returns: "javax.swing.plaf.ColorUIResource[r=255,g=255,b=255]" '

' font color '
component.getForeground().toString()
' returns: "java.awt.Color[r=255,g=255,b=180]" '

' font name, style, size '
component.getFont().toString()
' returns: "java.awt.Font[family=Tahoma,name=Tahoma,style=italic,size=11]" '

Otherwise you'd get a runtime error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.