Better / faster to draw an image as a button background or use Java2D to draw it

Say I have a button and you want to change the background button to a gradient, is it better / faster to draw a gradient using Java2D or just get an image with this gradient and put it in the background of the button?

+3
source share
3 answers

The only way to find out if this is faster is to measure it. Since changing the background color of a button depends on the appearance and style, I like to implement an interface Iconto decorate the button, as suggested in this.

+1
source

: .

: . .

: , .

+1

, . , , , , . , , , . , . , BufferedImage , , g.drawImage(Image img, int x, int y, ImageObserver observer) . , , BufferedImage 1 . , g.drawImage(Image img, int x, int y, int width, int height, ImageObserver observer).

However, worrying about what happens faster is usually pointless, although if you take 1 millisecond and the other takes 0.1 millisecond (unless you call it 1000 times per second). For more information, I would recommend Filthy Rich Clients, especially Chapters 4, 5, and 7.

0
source

Source: https://habr.com/ru/post/1762958/


All Articles