I want to change border of cell whenever it is selected regardless by mouse or by keyboard. It is hard to find smth on net. I tried to use ListSelectionListener but this doesn't work.
If you know some good way to change cell's border, please, reply. I welcome any ideas.
Thank you!
This is the default behaviour. The cell border is set based on the
Table.focusCellHighlightBorder
property of the table. So you can change the default Border by using the UIManager. See UIManager Defaults for more information.If for some reason this doesn't meet your requirements then I would check out Table Row Renderering which will allow you do this in one place instead of creating a custom renderer for every data type in your table.
Use a customized TableCellRenderer to do something different when the cell is selected.
http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#renderer
Looking at the code from the above example you can see how you would need to look at the
isSelected
boolean parameter.However, in your implementation just extend
DefaultTableCellRenderer
and call super() version ofgetTableCellRendererComponent
first and just change the cell color.