?
Solved

any way to insert newline in checkbox label

Posted on 2004-03-27
11
Medium Priority
?
355 Views
Last Modified: 2006-11-17
hi there,

I have a series of checkboes in an array called boxes. I assign the checkbox a string depending on the number of the checkbox

boxes[i] = new Checkbox(getString(i), boxGroup, false);

the getString function is as follows

 public String getString(int index) {
int uid = Integer.parseInt(details[index][UID]) - 1;
    switch (uid) {
      case PLAIN:
        return "Check " + details[index][URL] + " is updated";
      case PHRASE:
        return "Check " + details[index][URL] + "for " +  details[index][PHRASE1];
      case PHRASEPHRASE:
        return "Check " + details[index][URL] + " for " +  details[index][PHRASE1] + " followed by " + details[index][PHRASE2] +  "with " + details[index][DIST] + " characters between them.";
      case PHRASEVALUE:
        return "Check " + details[index][URL] + " for" + details[index][PHRASE1] + " followed by value " + details[index][OP] + " " + details[index][PHRASE2] + " with " + details[index][DIST] +
            " characters between them.";
      case VALUEPHRASE:
        return "Check " + details[index][URL] + " for value" + details[index][OP] + " " + details[index][PHRASE1] + " followed by " + details[index][PHRASE2] + " with " + details[index][DIST] + " characters between them.";

      default:
        return "";

    }

as you can see some of the strings are very long so I want the strings broken up into lines so it would look something like
O    Check http://www.geocities.com
      for password
      followed by protected
      with max chars between them 5

I've tried inserting the newline character \n into the strings where I want them but when the program is run its all on the one line with the square symbol in place of the \n.

any ideas?

thanks
0
Comment
Question by:mocarra
[X]
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
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 10694229
Specify the string as html and use a <br> as your line break.

eg.

return "<html><body>Check " + details[index][URL] + " for " +  details[index][PHRASE1] + "<br> followed by " + details[index][PHRASE2] +  "with " + details[index][DIST] + " characters between them.</body></html>";
0
 
LVL 2

Expert Comment

by:timbauer
ID: 10694269
Scrub the <body> tag though. It is not really necessary, nor are the closing tags.

return "<html>Check " + details[index][URL] + " for " +  details[index][PHRASE1] + "<br> followed by " + details[index][PHRASE2] +  "with " + details[index][DIST] + " characters between them.";

The <html> is just a quick hint to look for HTML in the label, it is not necessarly properly formed.

- Tim
0
 
LVL 92

Expert Comment

by:objects
ID: 10694275
> It is not really necessary, nor are the closing tags.

doesn't hurt though :)
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:mocarra
ID: 10694387
It doesnt seem to work now I just get

O <html>Check http://....etc

do I need to set anything in the checkbox properties?
0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 200 total points
ID: 10695004
In swing it works:

   JCheckBox myCheckBox = new JCheckBox();
   myCheckBox.setText("<HTML>Hello<BR>world!");

perfectly gives me a checkbox with two lines of text.

In your code snippet I read:

        boxes[i] = new Checkbox(getString(i), boxGroup, false);

So, you're using AWT checkboxes, no Swing JCheckBox's.
Maybe that's the reason.
0
 
LVL 92

Expert Comment

by:objects
ID: 10696130
> you're using AWT checkboxes, no Swing JCheckBox's.

Oops didn't notices that.
You cannot use line breaks using AWT
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10697845
with AWT, you'll have to build something yourself.
you can use an empty checkbox and several labels on a panel and add a mouse listener to the labels that toggles the state of the checkbox.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10712312
Thank you
:)
0
 

Author Comment

by:mocarra
ID: 10712353
thanks it worked perfectly...sorry about the delay computer crashed and had to reformat it...the joys of it!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10712426
>>  computer crashed and had to reformat it
I can imagine more pleasant tasks ;)
0
 
LVL 92

Expert Comment

by:objects
ID: 10718529
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 22 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