Is there an easy way to do word wrap for a JLabel?

Posted on 2005-03-03
Medium Priority
Last Modified: 2008-03-06
I want to use a JLabel to do word wrap. Is there an easy method to do this or is there another object that can perform the same function?
Question by:Marek_Zyskowski
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

JK2429 earned 252 total points
ID: 13452817
LVL 92

Assisted Solution

objects earned 248 total points
ID: 13453165
you should be able to achieve that using html for the label.
LVL 10

Expert Comment

ID: 13454599
Hi, Marek.

JK2429's link addresses ways to dynamically employ word-wrapping.  If that's not necessary, then as that link and object's comment state, you can employ <html> tags with a <br> tag:

     jLabel1.setText("<html>The king ran under<br> the hill.</html>");

The Java GUIs I've built are straight conversions of Visual Basic GUIs, so I've not been concerned with resizing the forms/components as per JK2429's link.  If that functionality is required, a more advanced approach will be necessary.  But the use of <html>/<br> tags is the simplest method of word-wrapping I've encountered.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question