views:

127

answers:

1
JCheckBox special = new JCheckBox ("\nSpecial - $17.95" + "\nMeatball, Sausage, Mushroom, Onion, Pepperoni & Pepper");

In this line of code, how do you make the checkbox make the "..." into two lines?

+6  A: 

The easiest way is to format it with HTML 3.2:

 JCheckBox checkBox = new JCheckBox("<HTML>" + "Special - $17.95"
   + "<BR>"
   + "Meatball, Sausage, Mushroom, Onion, Pepperoni & Pepper"
   + "</HTML>");

The alternative is to set a custom ButtonUI, though that is a considerably more involved approach.

McDowell
cool thanks but what are the <HTML>'s and <BR>?
How Swing supports HTML markup is described here: http://java.sun.com/docs/books/tutorial/uiswing/components/html.html - Follow this link for tag meanings: http://www.w3.org/TR/REC-html32
McDowell