I am trying to get the header on a table to have word wrap. I have managed to do this but the first data row is expanding. The code for the table is:
publi
You can achieve multi-line headers much easier.
As with many Swing components you can use HTML code. In HTML specify <br>
elements to indicate where line breaks / new lines should occur.
For example if you use the following header values (column names):
String[] columnNames = {
"<html>First<br>column</html>",
"<html>Second<br>column</html>",
"<html>Third<br>column</html>"
};
Then the headers will be properly rendered in 2 lines. You don't even need to create/use a custom header renderer, the default header renderer properly handles HTML code.
Note: The header height will be determined by the height of the first column. So you have to use a 2-line HTML value for the first column too. If you only have 1 word for the first column, you may additionally add an empty second line like this: "<html>Select<br> </html>"