• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1091
  • Last Modified:

add image to JPanel

I dont know much about java but I need this answer fast. Whats the simplest way to add a picture to java?

public class pff extends JPanel
{

public void paint(Graphics g)
{
      g.setColor(Color.BLUE);
      g.fillOval(X, Y, 25, 25);
}

}

I've got something like that, I want to be able to change the oval to a picture on my hard drive, how do I do that?
0
rickyman35
Asked:
rickyman35
2 Solutions
 
sciuriwareCommented:
No, simple replace all by:

   JPanel p = new JPanel();
   p.add(new JLabel(picture));

picture should be an ImageIcon.

;JOOP!
0
 
rickyman35Author Commented:
I cant get it to show up, I add it to the paint method but nothing shows up. It lets me compile though.
0
 
CEHJCommented:
If you're going to do it like you wanted, do

public void paintComponent(Graphics g)
{
     g.setColor(Color.BLUE);
     g.fillOval(X, Y, 25, 25);
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Mayank SAssociate Director - Product EngineeringCommented:
>> I cant get it to show up, I add it to the paint method but nothing shows up.

What layout did you use on the container?
0
 
sciuriwareCommented:
Please split.

;JOOP!
0
 
girionisCommented:
Opps... Sorry I meant to do a split only between CEJH and sciuriware, moderator please correct.

Regards
0
 
Mayank SAssociate Director - Product EngineeringCommented:
no problem.
0
 
sciuriwareCommented:
:))
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now