Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6849331

Nimbus L&F: AbstractRegionPainter's paint context is not initialized

XMLWordPrintable

    • b68
    • generic
    • generic

        When creating an instance of AbstractRegionPainter and then trying to invoke decodeX(), decodeY(), decodeAnchorY() etc. methods a NullPointerException is thrown.

        Please see the following code sample:

        import javax.swing.*;
        import java.awt.*;

        public class TestARP {

            public static void main(String[] args) {
                class MyARP extends javax.swing.plaf.nimbus.AbstractRegionPainter {
                    protected PaintContext getPaintContext() {
                        return null;
                    }
                    protected void doPaint(Graphics2D g, JComponent c,
                                           int width, int height,
                                           Object[] extendedCacheKeys) {
                    }
                    public void callDecodeAnchorX() {
                        decodeX(0.5f);
                    }
                }
                new MyARP().callDecodeAnchorX();
            }
        }
        -----------------------------------------
        output will be:

        Exception in thread "main" java.lang.NullPointerException
        at javax.swing.plaf.nimbus.AbstractRegionPainter$PaintContext.access$100(AbstractRegionPainter.java:472)
        at javax.swing.plaf.nimbus.AbstractRegionPainter.decodeX(AbstractRegionPainter.java:233)
        at TestARP$1MyARP.callDecodeAnchorX(TestARP.java:16)
        at TestARP.main(TestARP.java:19)

              peterz Peter Zhelezniakov
              dbessono Dmitry Bessonov
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: