Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Text line wrapping in JLabel and JList

719 views
Skip to first unread message

Amir Kost

unread,
Nov 26, 2001, 11:06:01 AM11/26/01
to
Hi.
Can anyone tell me how to wrap text lines JLabel and JList?

Regards,

Amir Kost


Paul Lutus

unread,
Nov 26, 2001, 11:30:22 AM11/26/01
to
"Amir Kost" <ko...@textology.com> wrote in message
news:3c02...@news.bezeqint.net...

> Hi.
> Can anyone tell me how to wrap text lines JLabel and JList?

Try using HTML. If your Java version is recent, it will work.

--
Paul Lutus
www.arachnoid.com


Linda Radecke

unread,
Nov 26, 2001, 1:46:13 PM11/26/01
to

Amir Kost wrote:

> Hi.
> Can anyone tell me how to wrap text lines JLabel and JList?

With JList this should not be an issue, actually; typically
you have your data stored in a ListModel, for instance:

DefaultListModel model = new DefaultListModel();
model.addElement(....);
JList list = new JList();

Did you check the tutorial with respect to JList/ListModel:
http://java.sun.com/docs/books/tutorial/uiswing/components/list.html

? When your data a stored in a Database this will correspond
to a column in your database, and should neither be a problem.


Linda
--
_ _ /--\ "I can't explain myself, I'm afraid,Sir",
\/_ _ _/(_(_(_o o) said Alice, "because I'm not myself,
(_(_(_(/ ^ you see". I don't see, said the Caterpillar.
Alices Adventures in Wonderland


Linda Radecke

unread,
Nov 26, 2001, 1:47:40 PM11/26/01
to

Amir Kost wrote:

> Hi.
> Can anyone tell me how to wrap text lines JLabel and JList?

With JList this should not be an issue, actually; typically


you have your data stored in a ListModel, for instance:

DefaultListModel model = new DefaultListModel();
model.addElement(....);

JList list = new JList(model);

Amir Kost

unread,
Nov 27, 2001, 5:27:39 AM11/27/01
to

"Paul Lutus" <nos...@nosite.zzz> wrote in message
news:y6uM7.106744$qx2.6...@bin5.nnrp.aus1.giganews.com...

What I meant is if it is possible to set the width of a JLabel or JList, so
the text will wrap if needed, instead of showing a scroll.

Amir


Linda Radecke

unread,
Nov 27, 2001, 9:59:32 AM11/27/01
to

Amir Kost wrote:

> What I meant is if it is possible to set the width of a JLabel or JList, so
> the text will wrap if needed, instead of showing a scroll.

Even if you restrict the width your text will not wrap. To get a
multiline JLabel you can use HTML, if you like that. But perhaps
you are rather looking for a JTextArea instead of JLabel or JList,
and turn on line-wrap: setLineWrap(true);/setWrapStyleWord(true);

Linda
--
(=)
/ li...@jalice.ch - http://www.jalice.net
(=)
/ l.ra...@hswzfh.ch - http://www.hswzfh.ch
(=)


Jan Cuypers

unread,
Nov 27, 2001, 1:13:34 PM11/27/01
to

"Amir Kost" <ko...@textology.com> wrote in message
news:3c03...@news.bezeqint.net...
>
[..]

>
> What I meant is if it is possible to set the width of a JLabel or JList,
so
> the text will wrap if needed, instead of showing a scroll.
>

Use a JTextArea and
- turn on word + line wrapping
- replace the caret with an invisible one
- set the cursor to default (not I-beam)
- install colors and fonts of a Label.
- disable focus traversal

This will look like and feel like a JLabel, but wraps its
contents according the width.

jan


0 new messages