Swing - How to get the Background Color of a JTable

Hi all!

I've got a problem to get the background color of a JTables cell.

I've tried

table.getComponentAt(r,c).getBackground();

which returns allways white (althoug there are colored cells)

I also tried

table.getCellRenderer(r,c).getTableCellRendererComponent(table,table.getValueAt(r,c),true,true,0,0).getBackground();

which allways returns a light blue color (i guess the default swing blue color).

Hopefully someone can help me with this.

Thanks in advance and with best regards

Hotkey

[686 byte] By [Hotkey_gera] at [2007-11-26 23:19:09]
# 1

hmm as far as i know table.getComponentAt(r,c) will not return the real actual component but rather a fake component that looks like the real one... (if you have buttons in there, they would not be clickable with out futher modifications)

i would suggest you handle the color getting/setting inside of your model!

What kind of model do you use or how do you add cells?

jEti182a at 2007-7-10 14:21:38 > top of Java-index,Desktop,Core GUI APIs...
# 2

You pass true to the isSelected parameter so you always get the color of a selected cell.

table.getCellRenderer(r,c).getTableCellRendererComponent(table,table.getValueAt(r,c),table.isRowSelected(r),false,r,c).getBackground();

Rodney_McKaya at 2007-7-10 14:21:38 > top of Java-index,Desktop,Core GUI APIs...
# 3
That was the mistake, shame on me and thanks for the help!
Hotkey_gera at 2007-7-10 14:21:38 > top of Java-index,Desktop,Core GUI APIs...