2 Replies Latest reply on Feb 10, 2011 4:53 PM by 838392

    Graphics setComposite

    838392
      Hello,

      I would like to define my own Composite in the paint method:

      <pre>
      public void paint(Graphics g) {
      super.paint(g);
      Graphics2D g2 = (Graphics2D) g;
      ac = new MyComposite();
      g2.setComposite(ac);
      g2.setColor(Color.green);
      g2.fillRect(0, 0, 100, 100);
      }

      class MyComposite implements Composite {
      @Override
      public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) {
      return AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f).createContext(srcColorModel,
      dstColorModel, hints);
      }
      }
      </pre>

      It works if I use the AlphaComposite factory: ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);

      Do you have any idea of how can I define my own Composite class?

      This is the complete stacktrace:

      Exception in thread "AWT-EventQueue-0" java.lang.InternalError: not implemented yet
           at sun.java2d.x11.X11SurfaceData.getRaster(X11SurfaceData.java:186)
           at sun.java2d.pipe.GeneralCompositePipe.renderPathTile(GeneralCompositePipe.java:82)
           at sun.java2d.pipe.SpanShapeRenderer$Composite.renderBox(SpanShapeRenderer.java:42)
           at sun.java2d.pipe.SpanShapeRenderer.renderRect(SpanShapeRenderer.java:145)
           at sun.java2d.pipe.SpanShapeRenderer.fill(SpanShapeRenderer.java:87)
           at sun.java2d.pipe.PixelToShapeConverter.fillRect(PixelToShapeConverter.java:44)
           at sun.java2d.pipe.ValidatePipe.fillRect(ValidatePipe.java:58)
           at sun.java2d.SunGraphics2D.fillRect(SunGraphics2D.java:2265)
           at CompositeColorsAdditive.paint(CompositeColorsAdditive.java:127)
           at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:796)
           at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
           at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
           at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
           at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
           at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
           at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
           at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
           at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
           at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

      Thanks!

      Edited by: user11205797 on 09.02.2011 15:15
        • 1. Re: Graphics setComposite
          800119
          I did a simple Google search of your error and came up with this, which looks like someone experiencing the same problem. A workaround was to set -Dsun.java2d.pmoffscreen=false.
          • 2. Re: Graphics setComposite
            838392
            Hello,

            Thank you for the answer. Unfortunately, this workaround does not work for me:

            <pre>
            $ java -Dsun.java2d.pmoffscreen=false CompositeColorsAdditive
            Exception in thread "AWT-EventQueue-0" java.lang.InternalError: not implemented yet
                 at sun.java2d.x11.X11SurfaceData.getRaster(X11SurfaceData.java:186)
            </pre>

            Do you have any other ideas? Do I miss something?

            Thanks,