Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly painting a JProgressBar which has no parent component will throw NPE #51

Open
FirokOtaku opened this issue Mar 13, 2019 · 0 comments

Comments

@FirokOtaku
Copy link

If a JProgressBar has no parent component, trying to paint it on a Graphics will throw NullPointerException.

The following code

try
{
    UIManager.setLookAndFeel(DarculaLaf.class.getName());
}catch (Exception e){}

JProgressBar bar=new JProgressBar();
bar.setSize(1,1);
Graphics gra
	=new BufferedImage(bar.getWidth(),bar.getHeight(),BufferedImage.TYPE_INT_RGB)
	.getGraphics();
bar.print(gra);

will throw a NPE at this line: bar.print(gra);

Exception in thread "main" java.lang.NullPointerException
    at com.bulenkov.darcula.ui.DarculaProgressBarUI.paintDeterminate(DarculaProgressBarUI.java:124)
    at javax.swing.plaf.basic.BasicProgressBarUI.paint(BasicProgressBarUI.java:412)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:161)
    at javax.swing.JComponent.paintComponent(JComponent.java:780)
    at javax.swing.JComponent.printComponent(JComponent.java:1220)
    at javax.swing.JComponent.paint(JComponent.java:1060)
    at javax.swing.JComponent.print(JComponent.java:1202)
    at firok.test.Test.main(Test.java:27)

and here is the source code where program crashed ( DarculaProgressBarUI::paintDeterminate:124 )

g.setColor(c.getParent().getBackground());

for now the resolution is

AWTAccessor.getComponentAccessor().setParent(bar,jPanel);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant