From 256482a739e134ce940790d85ee51d10325ea06d Mon Sep 17 00:00:00 2001 From: ray Date: Wed, 26 Jun 2002 17:27:51 +0000 Subject: [PATCH] Don't layout more lines than there are words in the text, to prevent single words being wrapped into two-line labels. git-svn-id: https://samskivert.googlecode.com/svn/trunk@785 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- projects/samskivert/src/java/com/samskivert/swing/Label.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/swing/Label.java b/projects/samskivert/src/java/com/samskivert/swing/Label.java index c384626a..28556a17 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/Label.java +++ b/projects/samskivert/src/java/com/samskivert/swing/Label.java @@ -1,5 +1,5 @@ // -// $Id: Label.java,v 1.13 2002/06/21 03:05:13 mdb Exp $ +// $Id: Label.java,v 1.14 2002/06/26 17:27:51 ray Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2002 Michael Bayne @@ -40,6 +40,7 @@ import java.text.AttributedCharacterIterator; import java.util.ArrayList; import java.util.HashMap; +import java.util.StringTokenizer; import javax.swing.SwingConstants; @@ -213,6 +214,7 @@ public class Label implements SwingConstants TextLayout layout = new TextLayout(textIterator(gfx), frc); Rectangle2D bounds = layout.getBounds(); int lines = Math.round(_constraints.height / getHeight(layout)); + lines = Math.min(lines, new StringTokenizer(_text).countTokens()); lines = Math.max(lines, 1); int targetWidth = (int)Math.round(bounds.getWidth() / lines);