What does setBackground(getBackground()) do?

306 views Asked by At

From the code snippet...

if ((Boolean) getModel().getValueAt(modelRow, 4)) {
    c.setBackground(Color.GREEN);
    repaint();
} else {
    c.setBackground(getBackground());

If the background is currently Color.GREEN, c.setBackground(getBackground()) seems to reset the background of the cell to the default colour of the table. This is what I want it to do, but I don't understand why. Surely getBackground() returns Color.GREEN, then c.setBackground(getBackground()) sets the background of the cell to green - i.e. it doesn't change.

Could someone please explain what's going on here?

Many thanks,

Gary

1

There are 1 answers

1
SatA On BEST ANSWER

Notice that the getBackground() method is not called under the object c

That is - not like this: c.getBackground()

Perhaps that is the reason? e.g getBackground() simply returns the color of the table? or some default?

Maybe the function is a static one? or of another object? without too much context it is difficult to say for sure..