Catch weird sporadic error that is occasionally thrown when label layout

results from the initial call to pack() on a Frame when an application
first starts up.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@852 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2002-09-25 08:42:00 +00:00
parent 64355cce3c
commit 412d26b2d4
@@ -1,5 +1,5 @@
// //
// $Id: Label.java,v 1.19 2002/09/23 21:19:06 shaper Exp $ // $Id: Label.java,v 1.20 2002/09/25 08:42:00 mdb 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
@@ -303,28 +303,35 @@ public class Label implements SwingConstants, LabelStyleConstants
{ {
// start with a size of zero // start with a size of zero
double width = 0, height = 0; double width = 0, height = 0;
// obtain our new dimensions by using a line break iterator to lay
// out our text one line at a time
ArrayList layouts = new ArrayList(); ArrayList layouts = new ArrayList();
TextLayout layout;
int lastposition = _text.length();
while ((layout = measurer.nextLayout(
targetWidth, lastposition, keepWordsWhole)) != null) {
Rectangle2D bounds = layout.getBounds(); try {
width = Math.max(width, bounds.getWidth()); // obtain our new dimensions by using a line break iterator to
height += getHeight(layout); // lay out our text one line at a time
layouts.add(new Tuple(layout, bounds)); TextLayout layout;
} int lastposition = _text.length();
while ((layout = measurer.nextLayout(
targetWidth, lastposition, keepWordsWhole)) != null) {
// fill in the computed size; for some reason JDK1.3 on Linux Rectangle2D bounds = layout.getBounds();
// chokes on setSize(double,double) width = Math.max(width, bounds.getWidth());
size.setSize(Math.round(width), Math.round(height)); height += getHeight(layout);
layouts.add(new Tuple(layout, bounds));
}
// this can only happen if keepWordsWhole is true // fill in the computed size; for some reason JDK1.3 on Linux
if (measurer.getPosition() < lastposition) { // chokes on setSize(double,double)
return null; size.setSize(Math.round(width), Math.round(height));
// this can only happen if keepWordsWhole is true
if (measurer.getPosition() < lastposition) {
return null;
}
} catch (Throwable t) {
Log.warning("Label layout failed [text=" + _text +
", t=" + t + "].");
Log.logStackTrace(t);
} }
return layouts; return layouts;