0

I have to write a multi-line text inside the header cells of a JTable.

For this reason, I'm using HTML this way (this is an example):

     JTable.getModel().getColumnModel().getColumn(i).setHeaderValue("
    <html>
          <div style='width:100%;height:300px;overflow:hidden'>
               <div style='width:100%;height:150px;overflow:hidden'>
                       text of line 1
               </div>
               <div style='width:100%;height:150px;overflow:hidden'>
                        text of line 2
               </div>
         </div>
   </html>
    ");  

I want set the inner div a 100% width and 150px height. But seems that height, width and overflow doesn't work.

What is my error?

2
  • 1
    The Swing HTML rendering engine (a subset of HTML 3.2) does not support most CSS. I doubt it would handle overflow:hidden. Commented Jun 1, 2019 at 13:41
  • Thank you. I used a <table> because I had to force every line not to break, so I used <td nowrap>, accepted by HTML 3.2 :) Commented Jun 8, 2019 at 12:33

1 Answer 1

1

I have to write a multi-line text inside the header cells of a JTable.

Keep the HTML simple:

setHeaderValue("<html>Line1<br>line2<br>&nbsp</html>");

The above will allow for 3 lines of text (for all columns of the header).

Note: the height of the header is determined by the height of the renderer in the first column.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your help. I used a <table> because I had to force every line not to break, so I used <td nowrap>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.