[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: fixed getPreferredSize in javax.swing.plaf.basic.Basic
From: |
Roman Kennke |
Subject: |
[cp-patches] FYI: fixed getPreferredSize in javax.swing.plaf.basic.BasicProgressBarUI |
Date: |
Fri, 13 May 2005 14:42:56 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204 |
I fixed the getPreferredSize() method so that it does not call
getGraphics() on the progressbar. This triggered a NPE when trying to
start Batik. I suppose that could be an AWT bug (getGraphics() should
not return null, should it?), but this workaround seems to work fairly well.
This closes bug #12449
2005-05-13 Roman Kennke <address@hidden>
* javax/swing/plaf/basic/BasicProgressBarUI.java
(getPreferredSize): Changed implementation so that getGraphics()
is not used (this triggers a NPE).
/Roman
Index: javax/swing/plaf/basic/BasicProgressBarUI.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicProgressBarUI.java,v
retrieving revision 1.8
diff -u -r1.8 BasicProgressBarUI.java
--- javax/swing/plaf/basic/BasicProgressBarUI.java 26 Jan 2005 23:32:51
-0000 1.8
+++ javax/swing/plaf/basic/BasicProgressBarUI.java 13 May 2005 12:36:54
-0000
@@ -48,6 +48,9 @@
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.font.FontRenderContext;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@@ -381,16 +384,16 @@
{
// The only thing we need to worry about is
// the text size.
- Graphics g = progressBar.getGraphics();
-
Insets insets = c.getInsets();
- FontMetrics fm = g.getFontMetrics(c.getFont());
-
- int textW = fm.stringWidth(progressBar.getString());
- int textH = fm.getHeight();
-
- g.dispose();
+ // make a fontrenderer context so that we can make assumptions about
+ // the string bounds
+ FontRenderContext ctx = new FontRenderContext(new AffineTransform(),
+ false, false);
+ Rectangle2D bounds = c.getFont().getStringBounds(progressBar.getString(),
+ ctx);
+ int textW = (int) bounds.getWidth();
+ int textH = (int) bounds.getHeight();
if (progressBar.getOrientation() == JProgressBar.HORIZONTAL)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: fixed getPreferredSize in javax.swing.plaf.basic.BasicProgressBarUI,
Roman Kennke <=