Interesting question. A quick Google doesnt reveal any subclasses for Graphics2d - maybe they are private?
You could do something that gives you a Graphics2d object (eg overide paintComponent) then test the runtime variable to see exactly what class it really is. With the actual class name it may be easier to track down the source.
Thise are examples of code that uses fillPolygon, but the OP was asking where to find the source code for fillPolygon. It's defined in Graphics, but its abstract. Graphics2D doesn't have an implemention either, so somewhere there is one or mode non-abstract subclasses that have a concrete implementation.
I just tried printing the class of the Graphics parameter in a simple Swing application and its sun.java2d.SunGraphics2D
so that's where the spource code will be!
original Java by Sun was about enthusiasm, tons of API has lack in descriptions (authors of description were inspired by MSDN:-)
almost, maybe all methods used for Graphics/Graphics2D, available in paint/paintChildren/paintBorder/paintIcon/paintComponent/paintImmediatelly are abstract, part of them is protected (thats one of reasons to declare the paintComponent protected too), just to avoids against an accesses, narrow the penetration from/to uninialized class, void, methods, variables
those methods couldn't be accessed from outside, only inside (e.g.) paintComponent, otherwise (dirty casting from outside is possible) result should be exception from RepaintManager,
I think thit is top of the safest implementations in compare with AWT methods draw()
paintImmediatelly must be call out of EDT (only if isEventDispatchThread returs false) otherwise RepaintManager can lock current JVM instance, forever
Thanks for your help , I was not able to find the code .
used anyother workaround which is not efficient.
background of this problem : I'm drawing multiple Rect/Polygons on JPanel and few Rect/Poly are filled with TexturePatterns wherein brackground is black and patterns(45/135 lines) are drawn in some colour
when I'm filling with this TexturePattern , I want the backgound image to be transparent i.e whereever there is black pixel filling should not happen , this will give transparent effect and easiest way is to override fillRect/Polygon code
In my workaround instead of fillRect/Polygon I've used drawRect/Polygon and used drawLine to created needed patterns !!
- Nataraja G
Change the BufferedImage to TYPE_INT_ARGB (RGB plus alpha channel). The alpha value (0-255) specifies how opaque the color is.
Instead of black, use a totally transparent color, eg new Color(0,0,0,0) (the fourth parameter is the alpha value)
and finally make the JPanel transparent (not opaque) using setOpaque(false)