Java JTable header word wrap

前端 未结 1 1996
别跟我提以往
别跟我提以往 2021-01-03 06:18

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         


        
1条回答
  •  青春惊慌失措
    2021-01-03 07:23

    You can achieve multi-line headers much easier.

    As with many Swing components you can use HTML code. In HTML specify
    elements to indicate where line breaks / new lines should occur.

    For example if you use the following header values (column names):

    String[] columnNames = {
        "First
    column", "Second
    column", "Third
    column" };

    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: "Select
     "

    0 讨论(0)
提交回复
热议问题