Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

scrollRectToVisible generating NullPointerException intermittently

13 views
Skip to first unread message

John Prestel

unread,
Jun 21, 2006, 3:56:25 PM6/21/06
to
This is a VERY intermittent problem. I'm testing scrolling around in a
JTable/JScrollPane. I use 2 for loops to scroll between the first 20 rows in
the table with 200 repetitions. There is no pattern for the Exception
generation. Most of the time it works, and sometimes it doesn't.

The function that calls scrollRectToVisible does 2 things.

First, it changes an integer in the CellRenderer object (custom renderer,
implements TableCellRenderer). When drawing the JTable, my renderer simply
checks the row # of the cell against this integer, and if they match it
changes the background color from white to green. So there is a change to the
graphics, but everything else about the table and window stay the same
(dimensions, etc.).

Second, it uses getCellRect() method of JTable to calculate the rectangle for
the first cell in row X and then calls scrollRectToVisible to scroll to that
row.

Here is the relevant code. If you think it's necessary to see the code for
the Cell Renderer, Table Model and/or the Table itself (the way it's
constructed) let me know and I'll update the thread with it.
####################################

This is loop used for testing:

for (int i=0; i<200; i++)
{
for (int j=0; j<20; j++)
{
frame.highlightRow(j);
}
}

And here is the function highlightRow ( int )

public void highlightRow(int row)
{
// Indicate the selected row to the Cell Renderer
( (ScriptDisplayCellRenderer) myCellRend).setSelectedRow(myTable,
selectedRow);

// Scroll the viewport to make the row visible
myTable.scrollRectToVisible( myTable.getCellRect(row, 0, false) );
}

#####################################
I stupidly didn't copy the stack trace the last time it generated the
exception.

However, I did get another anomaly that may be related. It also randomly
occurs.

Something more... I was running it just now to get a stack trace to show you
guys and something else just kicked off a NPE. The Exception did not kill the
program... it kept going, but I'm not pleased it popped up at all. Here's the
trace:

java.lang.NullPointerException

at javax.swing.plaf.basic.BasicTextUI$RootView.paint(BasicTextUI.java:1316)

at javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:636)

at javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:770)

at javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:749)

at javax.swing.JComponent.paintComponent(JComponent.java:541)

at javax.swing.JComponent.paint(JComponent.java:808)

at javax.swing.CellRendererPane.paintComponent(CellRendererPane.java:134)

at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:1150)

at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1051)

at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:974)

at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)

at javax.swing.JComponent.paintComponent(JComponent.java:541)

at javax.swing.JComponent.paint(JComponent.java:808)

at javax.swing.JComponent.paintChildren(JComponent.java:647)

at javax.swing.JComponent.paint(JComponent.java:817)

at javax.swing.JViewport.paint(JViewport.java:722)

at javax.swing.JComponent.paintChildren(JComponent.java:647)

at javax.swing.JComponent.paint(JComponent.java:817)

at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4787)

at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4740)

at javax.swing.JComponent._paintImmediately(JComponent.java:4685)

at javax.swing.JComponent.paintImmediately(JComponent.java:4488)

at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)

at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run
(SystemEventQueueUtilities.java:117)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.
java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.
java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

John Prestel via JavaKB.com

unread,
Jun 27, 2006, 8:20:26 AM6/27/06
to
^bump

--
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-gui/200606/1

0 new messages