Expand JList row height depending on content

后端 未结 3 1353
长情又很酷
长情又很酷 2020-12-21 05:48

I have a simple problem which totally drives me crazy.

I have a JList, and would like its cells to expand depending on their content, which is text of variable lengt

3条回答
  •  天涯浪人
    2020-12-21 05:55

    Not sure if there is an elegant way. One way that I know works is as follows : In getListCellRendererComponent()

    • Use JLabel for the renderer
    • Convert the text in question to HTML and use some logic to insert
      in to the text where desired.
    • Then set the text as text for the JLabel component and return.

提交回复
热议问题