Y.E.P
Y.E.P

Reputation: 1207

How do I put the data in the JTable in a new line but on the same row and why don't I see the horizontal scroll bars when needed?

I have to put large amount of text into the JTable. When I try to put the text into the JTable , it all goes all into a row without breaking a line like :

enter image description here

and there are no horizontal scroll bars also. Is there any way I can put the text in a new line but on the same row so that all the data is visible.If you notice the snapshot there are dots at the end I cannot see beyond them though there is still some text to be displayed.

I have tried increasing the height of the row but that doesn't help.

Note : I have done this in the constructor :

jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

Upvotes: 1

Views: 1184

Answers (2)

Andrew Thompson
Andrew Thompson

Reputation: 168825

You might use HTML formatting in am HTML component such as JLabel (the default renderer) or use a multi-line component such as JTextArea to render the content.

See also How to use Tables - Concepts: Editors and Renderers.

Upvotes: 1

MadProgrammer
MadProgrammer

Reputation: 347194

You're going to have to provide you're own table cell renderer.

Check out

The issue you're going to have is updating the row height of the individual rows. The JTable#rowHeight(row, height) method isn't tied to any model or renderer.

You can have a look at JTable multiline cell renderer for inspiration, but I'm not that keen on the idea of the cell rendered making decisions that may cause the table to re-render it-self.

You could override the prepareRenderer method of the JTable to do this, but that's getting pretty dirty to

Upvotes: 1

Related Questions