开发者

Lines of colored pixel

开发者 https://www.devze.com 2023-03-02 13:48 出处:网络
In a component I must display several lines of colored pixels.Each pixel of the line is given a color.What kind of component is suitable to build the line or what kind of component is suita开发者_运维

In a component I must display several lines of colored pixels. Each pixel of the line is given a color. What kind of component is suitable to build the line or what kind of component is suita开发者_运维问答ble to hold pixels?


Just extend JComponent and paint the lines/pixels in the paintComponent() method.


To me the best (but maybe not easiest) way would be implementing a custom Paint class that allows for setting colour regions - a bit like the GradientPaint classes but more flexible.

Then you would call Graphics2D.setPaint(myPaint) just before you draw the line.

The Paint implementation could offer a method setColorForRegion(double start, double end, Color color) with start and end taking values between 0.0 and 1.0 to mark a region on the line.

Might be a bit complicated to implement the Paint class, but the benefit is, that you can resize the lines and draw them in any direction while preserving the color pattern.

0

精彩评论

暂无评论...
验证码 换一张
取 消