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
This commit is contained in:
@@ -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
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2002 Michael Bayne
|
// Copyright (C) 2002 Michael Bayne
|
||||||
@@ -40,6 +40,7 @@ import java.text.AttributedCharacterIterator;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
@@ -213,6 +214,7 @@ public class Label implements SwingConstants
|
|||||||
TextLayout layout = new TextLayout(textIterator(gfx), frc);
|
TextLayout layout = new TextLayout(textIterator(gfx), frc);
|
||||||
Rectangle2D bounds = layout.getBounds();
|
Rectangle2D bounds = layout.getBounds();
|
||||||
int lines = Math.round(_constraints.height / getHeight(layout));
|
int lines = Math.round(_constraints.height / getHeight(layout));
|
||||||
|
lines = Math.min(lines, new StringTokenizer(_text).countTokens());
|
||||||
lines = Math.max(lines, 1);
|
lines = Math.max(lines, 1);
|
||||||
int targetWidth = (int)Math.round(bounds.getWidth() / lines);
|
int targetWidth = (int)Math.round(bounds.getWidth() / lines);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user