The JTable.getCellRect() method used to return a new Rectangle instance
on each call. This means that while painting a JTable we create one
Rectangle for each cell. This is not acceptable. The attached patch adds
a cached Rectangle instance that is always modified and returned
instead. Gives a nice boost in scrolling (wait for my next patch).
2006-02-13 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/JTable.java
(rectCache): New field.
(getCellRect): Returns cached Rectangle instance.
/Roman
Index: javax/swing/JTable.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTable.java,v
retrieving revision 1.69
diff -u -r1.69 JTable.java
--- javax/swing/JTable.java 9 Feb 2006 17:05:41 -0000 1.69
+++ javax/swing/JTable.java 14 Feb 2006 15:16:19 -0000
@@ -46,8 +46,6 @@
import java.awt.FontMetrics;
import java.awt.Point;
import java.awt.Rectangle;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
import java.awt.event.FocusListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@@ -86,7 +84,6 @@
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
-import javax.swing.text.Caret;
public class JTable
extends JComponent
@@ -1553,6 +1550,11 @@
private boolean surrendersFocusOnKeystroke = false;
/**
+ * A Rectangle object to be reused in [EMAIL PROTECTED] #getCellRect}.
+ */
+ private Rectangle rectCache = new Rectangle();
+
+ /**
* Creates a new <code>JTable</code> instance.
*/
public JTable ()
@@ -2001,9 +2003,10 @@
x += columnModel.getColumn(i).getWidth();
if (includeSpacing)
- return new Rectangle(x, y, width, height);
+ rectCache.setBounds(x, y, width, height);
else
- return new Rectangle(x, y, width - x_gap, height - y_gap);
+ rectCache.setBounds(x, y, width - x_gap, height - y_gap);
+ return rectCache;
}
public void clearSelection()
@@ -2090,7 +2093,7 @@
* Get the cell editor, suitable for editing the given cell. The default
* method requests the editor from the column model. If the column model
* does not provide the editor, the call is forwarded to the
- * [EMAIL PROTECTED] getDefaultEditor(Class)} with the parameter, obtained from
+ * [EMAIL PROTECTED] #getDefaultEditor(Class)} with the parameter, obtained from
* [EMAIL PROTECTED] TableModel#getColumnClass(int)}.
*
* @param row the cell row