Reputation: 23226
The following code produces error:
ImageIcon i=new ImageIcon("logo.png");
Image scaleImage=i.getImage().getScaledInstance(10,10,Image.SCALE_DEFAULT);
mainPanel.add(scaleImage);
The error is cannot find method add(Image)
.
Why it is giving this error?
Upvotes: 0
Views: 484
Reputation: 21329
ImageIcon i=new ImageIcon("logo.png");
Image scaleImage=i.getImage().getScaledInstance(70,70,Image.SCALE_DEFAULT);
ImageIcon ii=new ImageIcon(scaleImage);
JLabel pic=new JLabel(ii);
mainP.add(pic); // now you can add
Upvotes: 0
Reputation: 597106
You can't do it like that. JPanel
does not accept Image
as parameter (that's what the error tells you).
You have two options:
paintComponent(..)
method. JLabel
and an ImageIcon
The answers to this question will show you how to do it either way.
Upvotes: 1