Hi,
I have a JList that uses a custom cell renderer that implements JLabel
to display text. The problem is I want the text to automatically
wrap. I would use JTextArea instead of JLabel, except that I need to
display an image with the text, which to my knowledge JTextArea cannot
do. I am therefore stuck with using a JLabel, but I can't get the
text to wrap, and I would prefer to not dynamically insert <br> tags.
Any suggestions?
Thanks
Andrew Thompson - 30 Jan 2007 17:48 GMT
...
> I have a JList that uses a custom cell renderer that implements JLabel
> to display text. The problem is I want the text to automatically
[quoted text clipped - 3 lines]
> text to wrap, and I would prefer to not dynamically insert <br> tags.
> Any suggestions?
Most Swing components will render simple HTML.
Search the group/net for examples.
HTH
Andrew T.
Edwin Dankert - 31 Jan 2007 12:12 GMT
My suggestion would be to use a JPanel(BorderLayout) with a
JLabel(BorderLayout.WEST) (for the icon) and a JTextArea
(BorderLayout.CENTER) for the text. (I have never really warmed to
this HTML to style components idea)
Otherwise ... you might be able to use the QLabel [1] class for this,
it supports multiple lines.
Note: This is part of the bounce [2] package, which I have created
really only for myself, but feel free to use what ever you want. (It
uses an open source BSD license so, no restrictions :-)
[1] http://www.edankert.com/bounce/api/org/bounce/QLabel.html
[2] http://sourceforge.net/projects/bounce/
Regards,
Edwin
--
http://www.edankert.com/
Andrew Thompson - 31 Jan 2007 13:13 GMT
> My suggestion would be to use a JPanel(BorderLayout) with a
> JLabel(BorderLayout.WEST) (for the icon) and a JTextArea
> (BorderLayout.CENTER) for the text.
Now that I more closely examine the OP's
stated need, I agree with you.
The HTML suggestion did not account for
the wrapping of the text, at least not at
'natural line width' as opposed to coding
hard line breaks.
>...(I have never really warmed to
> this HTML to style components idea)
(shrugs) I have found it quite handy at
times, 'YMMV'.
Andrew T.
rhapsody1419@gmail.com - 15 Mar 2007 01:08 GMT
Have you tried wrapping your text in <html> and </html> tags? For some
reason, that makes it wrap for me.