[Patch][gui] javax.swing.JTextField

Michael Koch konqueror@gmx.de
Wed Dec 22 21:41:00 GMT 2004


Hi list,


I just committed the attached patch from GNU classpath to merge a fix
for getPreferredSize().


Michael


2004-12-22  Michael Koch  <konqueror@gmx.de>

	* javax/swing/JTextField.java
	(getPreferredSize): Re-implemented.

-------------- next part --------------
Index: javax/swing/JTextField.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JTextField.java,v
retrieving revision 1.2.18.9
diff -u -r1.2.18.9 JTextField.java
--- javax/swing/JTextField.java	13 Sep 2004 12:00:29 -0000	1.2.18.9
+++ javax/swing/JTextField.java	22 Dec 2004 21:36:55 -0000
@@ -35,6 +35,7 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
+
 package javax.swing;
 
 import java.awt.Dimension;
@@ -50,7 +51,6 @@
 import javax.swing.text.JTextComponent;
 import javax.swing.text.PlainDocument;
 
-
 public class JTextField extends JTextComponent
   implements SwingConstants
 {
@@ -272,19 +272,10 @@
 
   public Dimension getPreferredSize()
   {
-    Dimension size;
-    FontMetrics fm = getFontMetrics(getFont());
-    int fontHeight = fm.getMaxAscent() + fm.getMaxDescent();
-    int columnWidth = fm.charWidth('m');
-    
+    Dimension size = super.getPreferredSize();
+
     if (columns != 0)
-      {
-	size = new Dimension(columns * columnWidth + 4, fontHeight + 4);
-      }
-    else
-      {
-	size = new Dimension(10, 10);
-      }
+      size.width = columns * getColumnWidth();
 
     return size;
   }


More information about the Java-patches mailing list