Peoples, estou com tentando colocar uma imagem num JPanel só que tá me retornando um erro.
O código que estou usando é esse:
...
frame.getContentPane().setLayout (new BorderLayout());
pFundo.setLayout(new BorderLayout());
JLabel label = new JLabel(new ImageIcon("gradiente.jpg"));
pFundo.add(label, BorderLayout.CENTER);
frame.getContentPane().add(pFundo,BorderLayout.CENTER);
this.pack();
frame.setVisible(true);
...
e o erro é esse:
Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
at co.departamentodetransito.visao.TelaDeLogin.insereImagem(TelaDeLogin.java:297)
at co.departamentodetransito.visao.TelaDeLogin.pFundoAncestorAdded(TelaDeLogin.java:292)
at co.departamentodetransito.visao.TelaDeLogin.access$000(TelaDeLogin.java:11)
at co.departamentodetransito.visao.TelaDeLogin$1.ancestorAdded(TelaDeLogin.java:76)
at javax.swing.AncestorNotifier.fireAncestorAdded(AncestorNotifier.java:68)
at javax.swing.AncestorNotifier.componentShown(AncestorNotifier.java:175)
at java.awt.Component.processComponentEvent(Component.java:6095)
at java.awt.Component.processEvent(Component.java:6043)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Window.processEvent(Window.java:1836)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
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)
Espero que possam me ajudar