@@ -532,14 +532,7 @@ public void paintBackground(Graphics g, SynthContext context,
532532 native_paint_background (widget , state , x - x0 , y - y0 , w , h );
533533 }
534534
535- private static final ColorModel [] COLOR_MODELS = {
536- // Transparency.OPAQUE
537- new DirectColorModel (24 , 0x00ff0000 , 0x0000ff00 , 0x000000ff , 0x00000000 ),
538- // Transparency.BITMASK
539- new DirectColorModel (25 , 0x00ff0000 , 0x0000ff00 , 0x000000ff , 0x01000000 ),
540- // Transparency.TRANSLUCENT
541- ColorModel .getRGBdefault (),
542- };
535+ private static final ColorModel [] COLOR_MODELS = new ColorModel [3 ];
543536
544537 private static final int [][] BAND_OFFSETS = {
545538 { 0x00ff0000 , 0x0000ff00 , 0x000000ff }, // OPAQUE
@@ -609,15 +602,27 @@ public BufferedImage finishPainting(boolean useCache) {
609602 WritableRaster raster = Raster .createPackedRaster (
610603 dataBuffer , w0 , h0 , w0 , bands , null );
611604
612- ColorModel cm = COLOR_MODELS [ transparency - 1 ] ;
613- BufferedImage img = new BufferedImage (cm , raster , false , null );
605+ ColorModel cm = colorModelFor ( transparency ) ;
606+ BufferedImage img = new BufferedImage (cm , raster , true , null );
614607 if (useCache ) {
615608 cache .setImage (getClass (), null , w0 , h0 , cacheArgs , img );
616609 }
617610 graphics .drawImage (img , x0 , y0 , null );
618611 return img ;
619612 }
620613
614+ private ColorModel colorModelFor (int transparency ) {
615+ synchronized (COLOR_MODELS ) {
616+ int index = transparency - 1 ;
617+ if (COLOR_MODELS [index ] == null ) {
618+ COLOR_MODELS [index ] = GraphicsEnvironment .getLocalGraphicsEnvironment ()
619+ .getDefaultScreenDevice ().getDefaultConfiguration ()
620+ .getColorModel (transparency );
621+ }
622+ return COLOR_MODELS [index ];
623+ }
624+ }
625+
621626 /**
622627 * Notify native layer of theme change, and flush cache
623628 */
0 commit comments