1

How can I display multiple lines within a single cell of a JList. In jtable, it is achieved by adding a JTextarea to the table cell renderer. Similiarly, Is there any code to add a custom cell renderer for a JList that holds a textarea? If yes, can you please give me a code snippet for the same?

Or do you think there is any other better method to display multiple lines within the cell of Jlist instead of using a textarea? please help me!!

jmj
  • 237,923
  • 42
  • 401
  • 438
Vamsi Emani
  • 10,072
  • 9
  • 44
  • 71
  • 2
    possible duplicate of [Problem displaying components of JList](http://stackoverflow.com/questions/5631048/problem-displaying-components-of-jlist) – trashgod Apr 12 '11 at 09:44
  • please simply _do_ it: it's exactly the same mechanics as for a TableCellRenderer. If you did and experienced any problems, come back with the concrete question as to what doesn't work as you expected. – kleopatra Apr 12 '11 at 11:35

2 Answers2

5

Beside usage of HTML code in Swing component (like Jigar says), you can also specify a ListCellRenderer that uses a TextArea, exactly like you do in your JTable.

Community
  • 1
  • 1
Riduidel
  • 22,052
  • 14
  • 85
  • 185
3

Try with html.

"line one <br/> linetwo"
jmj
  • 237,923
  • 42
  • 401
  • 438
  • 1
    Remember to wrap your HTML with tags: "line one
    linetwo" http://stackoverflow.com/questions/3070484/can-items-in-a-jlist-be-formatted-as-html
    – Bjorn Mar 12 '14 at 13:35