[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: implemented getPreferredSize in JTextArea
From: |
Roman Kennke |
Subject: |
[cp-patches] FYI: implemented getPreferredSize in JTextArea |
Date: |
Fri, 10 Jun 2005 14:37:00 +0200 |
User-agent: |
Mozilla Thunderbird 1.0.2 (X11/20050317) |
Although I have marked bug #13259 as closed, my fix obviously was not
100% correct. I have simply set the preferredSize of JTextArea to a sane
value. The correct fix would have been to implement getPreferredSize and
return a value there which is computed from the rows and columns
properties as well as the size that is needed to display the content of
the JTextArea. This is fixed with the attached patch.
2005-06-10 Roman Kennke <address@hidden>
* javax/swing/JTextArea.java
(getPreferredSize): Implemented new method. This is overridden
in order to support custom set rows and columns.
/Roman
Index: javax/swing/JTextArea.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTextArea.java,v
retrieving revision 1.12
diff -u -r1.12 JTextArea.java
--- javax/swing/JTextArea.java 3 Jun 2005 13:26:06 -0000 1.12
+++ javax/swing/JTextArea.java 10 Jun 2005 12:27:57 -0000
@@ -47,6 +47,7 @@
import javax.swing.text.Element;
import javax.swing.text.JTextComponent;
import javax.swing.text.PlainDocument;
+import javax.swing.text.View;
/**
* The <code>JTextArea</code> component provides a multi-line area for
displaying
@@ -188,7 +189,6 @@
setText(text);
setRows(rows);
setColumns(columns);
- setPreferredSize(new Dimension(440, 150));
}
/**
@@ -529,4 +529,22 @@
// This cannot happen as we check offset above.
}
}
+
+ /**
+ * Returns the preferred size for the JTextArea. This is the maximum of
+ * the size that is needed to display the content and the requested size
+ * as per address@hidden #getColumns} and address@hidden #getRows}.
+ *
+ * @return the preferred size of the JTextArea
+ */
+ public Dimension getPreferredSize()
+ {
+ int reqWidth = getColumns() * getColumnWidth();
+ int reqHeight = getRows() * getRowHeight();
+ View view = getUI().getRootView(this);
+ int neededWidth = (int) view.getPreferredSpan(View.HORIZONTAL);
+ int neededHeight = (int) view.getPreferredSpan(View.VERTICAL);
+ return new Dimension(Math.max(reqWidth, neededWidth),
+ Math.max(reqHeight, neededHeight));
+ }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: implemented getPreferredSize in JTextArea,
Roman Kennke <=