Java swing rendering optimizations
I understand that Java's native swing UI elements do a number of rendering optimizations so it performs better. That said, if I had a customized JPanel (meaning, I've overriden its paintComponent method):
- Will rendering optimizations be performed still (as I would hope)?
- Can I manually tell its parent container when to repaint the JPanel? Said differently, can I freeze the re-rendering of the JPanel until explici开发者_StackOverflow中文版tly told so?
- If so (#2), can I tell it to repaint only a specific portion of the JPanel (smart painting, I think its called...)?
- And finally, will re-rendering the JPanel be able to handle transparency, rounded corners, or other non-rectangular shapes for the JPanel? (meaning it will re-render elements underneath the JPanel, I suppose)
If not, are there alternate techniques for faking it? (preferrably just a link to a source/reference I can read from)
To speed up the rendering you can use BufferedImage. Render your content once on the image's Graphics and use image instead of rendering all the content.
To render portion of panel use Graphics' setClip()/getClip() check which region has to be refreshed and draw only portion.
TO draw non rectangular object use the same setClip setting necessary Shapes.
精彩评论