Render graphics or use images
I am working on making my GUI's prettier :) Curious if it's better to
say draw a round button, and it's color, gradient, etc. in Java via
code. Or if I should make an image to use for the button instead.
For some reason I my gut tells me there is less overhead with using
images as opposed to rendering?
an image would be less code, but you have to swap out the image (usually) to indicate state of pressed or hover, if the standard button stuff doesn't do what you want.
custom drawing gives you more flexibility in some cases, but it takes some code and some drawing know-how to get anything fancy to be rendered.
As far as performance, there's probably not much difference.
You could custom draw an image on the fly and use the image on the button, of course.
Yeah I am currently coding and ran into the issue with up and down button states. I will still have icon images. I was just changing the shape and making the background and gradient. Just did not want to spend all the time coding the shape and gradient just to hose performance. When I could bang out some gradient button backgrounds.
So I figured if there was a performance difference I would let that be the deciding factor. Otherwise I guess it's just time to code vs time to create.
I would personally be fairly confident that rendering an image will generally be faster than painting via code. How much that difference is in reality obviously depends on the dimensions and complexity of your icons and of course how many of them you have on screen and how often they're repainted. And as mentioned above, you can always render via code to an image and cache it.
Images are generally fine but code-based rendering does offer advantages in some scenarios, notably it can cope better with extreme ranges of screen resolution. However, if you're using images then you can make them more attractive and clearer than you could if rendering in code.
Horses for courses: I can think of situations which would suit images, and situations which would suit code rendering. All depends what you're doing.
Yeah, custom painting can be slower. If you are using gradients and odd shapes, then that's going to create slowness compared to simple boxes and text. So a complex image is going to be faster. Plus it's easier to draw in Photoshop then write code to draw the same thing, in all but the simplest of cases.
If one is going to use images, and etc. Is it now preferred or recommended to use Synth LAF? Is there any benefit to using Synth to make a custom LAF as opposed to actually coding a LAF. Understood that Synth is to avoid coding for the most part. Just not sure if the performance is better/worse one way or another.