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
# 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?
# 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();