Hello there,
I have an app that draws lines of text on a canvas component. Canvas is put into a scrollpane and vertical scrolling is carried out when up or down keys are pressed. Text is first read from a text file and everything works perfectly for as long as the text file size is relatively small. When I try to use a text file that's about 150Kb in size (~21400 words / ~140700 chars), the program starts to work unpleasantly slowly, and scrolling doesn't go smoothly any more and becomes rather jerky.
Windows Task Manager says that about 20Mb of memory is used by my program when it works with a large file like that. That seems like _A LOT_...
My paint method isn't really overloaded with calculations. It just retrieves words and corresponding font sizes from ArrayLists and draws them, calculating coordinates for every
word and performing word wrapping and breaking if necessary as well.
It seems that the paint method works through the whole canvas drawing the text on it every time it's called. The canvas size gets really large when there's such a lot of text being drawn, but the scrollpane's viewport size is small, so we don't need to repaint the whole canvas as we don't see the most of it.
Is there any workaround here? Any common approach in cases like this that everybody knows but me?...
))