-2

Suppose my custom rendering takes long time. By what means can I render cells in background? Probably I need to receive event when some cell becomes visible, then render it in separate thread, then actually paint.

How to accomplish this?

UPDATE

I know the render should be fast. But it does not in my case. So, I need extra layer between presentation and model, which will contain some sort of cache. For example, images of prerendered cells. The question is about how to hook this layer to the object.

Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
  • 2
    You can use a SwingWorker do do the image creation, and have it return an Image or an Icon which is used by the Renderer, but as in most things, the devil exists in the details. If you need more specific help, then you first, please tell us more of the details and show us your pertinent code, preferably as a [minimal example program or MCVE](http://stackoverflow.com/help/mcve). – Hovercraft Full Of Eels Oct 19 '14 at 14:10
  • Currently I already have a model. And it takes long time to draw this model entry. It is a matter of fact. I won't refactor what model is just to speed up the rendering, because model should not contain visual part. – Suzan Cioc Oct 19 '14 at 15:57
  • 1
    [This example](http://stackoverflow.com/questions/13753562/adding-progress-bar-to-each-table-cell-for-file-progress-java/13755155#13755155) uses a `SwingWorker` to copy a file with the progress presented within a `JTable`, it might provide some ideas – MadProgrammer Oct 19 '14 at 23:52

1 Answers1

4

A render should be as fast as possible. A render should't do complex computation, just paint the model, not calculate it every time. Renders are called from EDT (Event Dispatch Thread), and I think, without more information, that maybe you should calculate the model in a separate thread, and the render just paint the model in the EDT. If the model is still not available, you could disable the component for example.

Post the code for more precise solution please.

Ezequiel
  • 3,477
  • 1
  • 20
  • 28
  • We have a proverb in Russia here about the case: "the wheat should mature in time and in sufficient amount". Khrushchev said this. I know that render should be fast. Everybody knows it. The question is what to do when it doesn't. – Suzan Cioc Oct 19 '14 at 15:48
  • 1
    +1, `The question is what to do when it doesn't.` and you have been given an answer the best we can since you refuse to post demo code even though you have been asked twice to do so. The basic answer is to pre-render. Without details of the rendering process and why it takes so long we can't suggest any more of a specific solution. – camickr Oct 19 '14 at 16:08