Hi, is possible to turn header text bold when I select a cell of its column? How to do it?
Thanks Leandro
Hi, is possible to turn header text bold when I select a cell of its column? How to do it?
Thanks Leandro
It is partially possible. What you have to do is write your model is such way that on table's cell selection your model executes fireTableStructureChanges method( assuming you use AbstractTableModel as a base). This will repaint the whole table including column header. All you have to do is keep the state of which column is selected.
In the beginning I said "partially" possible. That is because calling fireTableStructureChanges will revalidate the whole table and you will lose your current column model state - column widths and sequence.
To make your text bold you can use HTML - something like <html><b>your text</b></html>
, but it has to change dynamically based on your model's internal state
UPDATE: Also column table header text can be set directly but model change or tableStructureChanged event will make the table to reread from the model.
Set custom renderer into table header. If current column is selected column set font to bold.
JTable table = new JTable()
table.getTableHeader().setDefaultRenderer(new MyRenderer());
class MyRenderer implements TableCellRenderer {
//todo implement
}