在 Jlist 单元格中显示多行

问题描述:

如何在 JList 的单个单元格中显示多行.在 jtable 中,它是通过向表格单元格渲染器添加一个 JTextarea 来实现的.同样,是否有任何代码可以为包含 textarea 的 JList 添加自定义单元格渲染器?如果是的话,你能给我一个相同的代码片段吗?

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?

或者您认为还有其他更好的方法可以在 Jlist 的单元格内显示多行而不是使用 textarea 吗?请帮我!!

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!!

除了使用 Swing 组件中的 HTML 代码(例如 Jigar 说),你也可以指定一个 ListCellRenderer 使用 TextArea,就像您在 JTable 中所做的一样.

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.