Hi,
I am trying to use html text to the BlurJButton from thhsi example code.

http://codeidol.com/java/swing/Basic-JComponents/Blur-Disabled-Components/

However, I get a null pointer when I use html text, using normal text causes no 
problems.

Any help or hints would be welcome.
Thanks.

This is my full code:

public class MyButton extends JButton {

        /**
         * serialVersionUID.
         */
        private static final long serialVersionUID = 1241274818258250433L;

        /**
         * Constructs a default button.
         * 
         * @param arg0
         *            Button name
         */
        public MyButton(final String arg0) {
                super(arg0);
                setName(arg0);
                setVerticalTextPosition(SwingConstants.CENTER);
                setHorizontalTextPosition(SwingConstants.CENTER);
                setMargin(new Insets(0, 0, 0, 0));
        }

        private static String formatText(final String text) {
                return String.format("<html><center>%s</center></html>", text);
        }

        /**
         * Set the text for this button. The text will be formatted as a html 
tag.
         * @param text
         *              Text.
         */
        @Override
        public void setText(final String text) {
                super.setText(formatText(text));
        }
        
        public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if (isEnabled()) {
                        return;

                }
                BufferedImage buf = new BufferedImage(getWidth(), getHeight(),
                                BufferedImage.TYPE_INT_RGB);
                super.paintComponent(buf.createGraphics()); // <- Exception 
from here

                float[] my_kernel = { 0.10f, 0.10f, 0.10f, 0.10f, 0.20f, 0.10f, 
0.10f,
                                0.10f, 0.10f };
                ConvolveOp op = new ConvolveOp(new Kernel(3, 3, my_kernel));
                Image img = op.filter(buf, null);
                g.drawImage(img, 0, 0, null);
        }

}

This is the exception:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javax.swing.text.BoxView.paint(Unknown Source)
        at javax.swing.text.html.BlockView.paint(Unknown Source)
        at javax.swing.plaf.basic.BasicHTML$Renderer.paint(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonUI.paint(Unknown Source)
        at com.sun.java.swing.plaf.windows.WindowsButtonUI.paint(Unknown Source)
        at javax.swing.plaf.ComponentUI.update(Unknown Source)
        at javax.swing.JComponent.paintComponent(Unknown Source)
        at mypackage.MyButton.paintComponent(MyButton.java:64)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JLayeredPane.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paintToOffscreen(Unknown Source)
        at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
        at javax.swing.RepaintManager.paint(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
        at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
        at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
        at java.awt.Container.paint(Unknown Source)
        at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
        at 
javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
[Message sent by forum member 'uncletall' (uncletall)]

http://forums.java.net/jive/thread.jspa?messageID=284384

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to