diff --git a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java index f9f63076781..2540f6e7880 100644 --- a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java +++ b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java @@ -532,14 +532,7 @@ class GTKEngine { native_paint_background(widget, state, x - x0, y - y0, w, h); } - private static final ColorModel[] COLOR_MODELS = { - // Transparency.OPAQUE - new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000), - // Transparency.BITMASK - new DirectColorModel(25, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x01000000), - // Transparency.TRANSLUCENT - ColorModel.getRGBdefault(), - }; + private static final ColorModel[] COLOR_MODELS = new ColorModel[3]; private static final int[][] BAND_OFFSETS = { { 0x00ff0000, 0x0000ff00, 0x000000ff }, // OPAQUE @@ -609,8 +602,8 @@ class GTKEngine { WritableRaster raster = Raster.createPackedRaster( dataBuffer, w0, h0, w0, bands, null); - ColorModel cm = COLOR_MODELS[transparency - 1]; - BufferedImage img = new BufferedImage(cm, raster, false, null); + ColorModel cm = colorModelFor(transparency); + BufferedImage img = new BufferedImage(cm, raster, true, null); if (useCache) { cache.setImage(getClass(), null, w0, h0, cacheArgs, img); } @@ -618,6 +611,18 @@ class GTKEngine { return img; } + private ColorModel colorModelFor(int transparency) { + synchronized (COLOR_MODELS) { + int index = transparency - 1; + if (COLOR_MODELS[index] == null) { + COLOR_MODELS[index] = GraphicsEnvironment.getLocalGraphicsEnvironment() + .getDefaultScreenDevice().getDefaultConfiguration() + .getColorModel(transparency); + } + return COLOR_MODELS[index]; + } + } + /** * Notify native layer of theme change, and flush cache */