Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

580 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