File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTable slow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable slow" Watch "JTable slow" New topic

JTable slow

Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367

I have a JTable with rows and column that the user can remove and/or add.

My problem is that if the JTable rows becomes more then 15 and the columns become more then 10 the Jtable slows down. ALOT. When resizing columns with drag the JTable is very slow.

How can I come around this? I have a CellEditor which extends the DefaultCellEditor. Every column has the same editor. The cellrenderer implements the TableCellRenderer and sets a HTMLDocument to every cell. I have one Instance of a JTextPane but I have to do the JTextPane.setDocument in the getTableCellRendererComponent. If I don't set the document in the component the data is not displayed.

Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 356

speculation about the cause of the low performance is possible, but I don't recommend it. Use a profiler. Here is an example for invoking the profiler that is shipped with the JDK for your situation (JVM options):

Include these options in your normal program call. Then while the program is running you must do the things that take too long all of the time for a couple of seconds, then exit immediately. The result is in java.hprof.txt


Kai Witte's business website Kai Witte's private homepage
ak pillai
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
If you are doing any I/O bound or computationally intensive stuff, you should not do it in the dispatcher thread. The fundamental behind this is as follows.

The event-dispatching thread is a thread that executes drawing of components and event-handling code. For example the paint() and actionPerformed() methods are automatically executed in the event-dispatching thread. Another way to execute code in the event-dispatching thread from outside event-handling or drawing code, is using SwingUtilities invokeLater() or invokeAndWait() method. Swing lengthy initialization tasks (e.g. I/O bound and computationally expensive tasks), should not occur in the event-dispatching thread because this will hold up the dispatcher thread. If you need to create a new thread for example, to handle a job that�s computationally expensive or I/O bound then you can use the thread utility classes such as SwingWorker or Timer without locking up the event-dispatching thread.

java j2ee job interview questions with answers | Learn the core concepts and the key areas
I agree. Here's the link:
subject: JTable slow
It's not a secret anymore!