0

so i have a very basic java application, there is a panel and inside that is a button. When a user clicks the button, i want a picture to come up in another panel in the same form.

I searched up ways to load images from web/from my folder and this is the code i've come up with:-

private void buttonActionPerformed(java.awt.event.ActionEvent evt)

{                                       
    ImageIcon icon = new ImageIcon("URL-of-the-image");
    panel2.setIcon(icon);

}    

~~what panel 2 looks like~~

where am i going wrong? it says that the method "setIcon()" is causing a problem but i don't know any other method to do this job. Please Guide!

9
  • What is the problem? Commented Jun 8, 2017 at 9:38
  • for the method "setIcon", it says "cannot find symbol" Commented Jun 8, 2017 at 9:38
  • So it doesn't compile? Commented Jun 8, 2017 at 9:39
  • 1
    If it is a JPanel, it doesn't have a setIcon method, you may want to use a JLabel instead . Commented Jun 8, 2017 at 9:40
  • 2
    @Berger can you put your comment in an answer so that I can +1 it? Commented Jun 8, 2017 at 9:42

1 Answer 1

2

If panel2 is a JPanel, it doesn't have a setIcon method.

Use a JLabel instead , it has such a method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.