I want to have an ImageIcon in a JLabel that i will be able to update from another method. But I can’t figure out a way to be able to create a static JLabel(so as to be able to acccess it from another method) and also instaiate it as a Jlabel that contains an imageIcon – is there another method other than JLabel label = new JLabel(imgIcon) to create a label with an imageIcon? tried to use the setIcon method without the label being instatiated the way it is above but it gave a null pointer exception. Thanks in adavance for any help.
Share
Don’t make the JLabel static – instead define it outside of other methods but still in your class.
If you need to access it from another class, create an accessor method: