• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable Performance

 
J. Ryan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTable attached to a JScrollPane that uses a custom table cell renderer (a JLabel). My problem is that when several labels are "filled" with contents, the JTable scrolls at a terribly slow speed. Any ideas on how to improve the performance here?

Before you ask, I cannot scrap the JTable and use 2D or anything like that. The application already uses a JTable, and I am not able to change that.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post the code of your TableCellRenderer? Your description points to that as the culprit - as more labels (cells?) are filled, the performance gets worse.

(edit - removed name change request, first initials are valid.)
[ June 27, 2007: Message edited by: Nathan Pruett ]
 
J. Ryan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the general pseudo-code:



The method above has many if statements to determine the exact look of the label. In most cases, it just returns a JLabel without much being done to it. The problem is when many cells are created with actual contents, the table slows down incredibly.

I've thought about doing something using Java2D, but it would mean way to much refactoring of existing code. Is there any way to improve the speed without totally throwing away the JTable?
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refactoring aside, I don't see how Java2D would help any.

What happens if you change extends JLabel implements TableCellRenderer
to extends DefaultTableCellRenderer?

DefaultTableCellRenderer extends JLabel so you shouldn't have to change the rest of your code. If it's really all the if statements that are causing the problem then this won't help much, but if it's the Component validation stuff then it could help.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
once i had a very very slow scrolling and used something like this:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!