0

I have a JTable, I Want to present a String of text containing "\r\n" which represent new lines. And I want these new lines to show in the table and not just be ignored. A visual representation of my problem follows.

Today:

|Titel           |
------------------
|texttex ttext xt|
------------------

Goal:

  |Titel   |
  ----------
  |texttex |
  |ttext xt|
  ----------

I have experimented with JTextPane but my result is a textual representation of that object instead of a text encapsulated in a JTextPane..(Maybe I don't understand all those obvious internet guides).

To summarize the question, how do I present a column in a JTable which contains multiple lines without having a indexation for each line. (or basic instructions of how to really make the JTextPane work in a column..?)

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Pewdut
  • 35
  • 2
  • 9

2 Answers2

4

I would suggest either you use <br> instead of \r\n or you set a TableCellRenderer on your JTable. The TableCellRenderer would return a JTextPane when it is called - create only one instance of JTextPane and return it for each call (after having set the appropriate value)

Luca
  • 9,259
  • 5
  • 46
  • 59
dotvav
  • 2,808
  • 15
  • 31
3

see JTable tutorial,

  1. basic instructions of how to realy make the JTextPane

  2. event is example about JTextArea, have to change to JTextPane and to add JTextPane#setContentType(text/html), look into API

  3. issue could be with SystemLookAndFeel and JTextPane as JTables Renderer

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319