Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2007

Tip: Looking for answers? Try searching our database.

JLabel Text Wrap

Thread view: 
Ooder - 30 Jan 2007 15:45 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.