Zolf
asked on
help with inserting image
hello there,
i have this simple frame class to which i want to add a image.how can i do.
cheers
zolf
import javax.swing.*;
import java.awt.*;
public class ImageFrame extends JFrame
{
public ImageFrame()
{
super("My Frame");
Container c = getContentPane();
c.setLayout(new BorderLayout());
setSize(300,300);
setLocation(100, 100);
setVisible(true);
}
public static void main(String [] args)
{
new ImageFrame();
}
}
i have this simple frame class to which i want to add a image.how can i do.
cheers
zolf
import javax.swing.*;
import java.awt.*;
public class ImageFrame extends JFrame
{
public ImageFrame()
{
super("My Frame");
Container c = getContentPane();
c.setLayout(new BorderLayout());
setSize(300,300);
setLocation(100, 100);
setVisible(true);
}
public static void main(String [] args)
{
new ImageFrame();
}
}
c.add(new JLabel(new ImageIcon("x.jpg")));
ASKER
i want the frame to be the size of the image.automatically the frame should resize to the image size
ASKER
i tried this,to some extend it works.i mean the height of the frame is little smaller then the image size.i have to resize the frame to view the image.what could be wrong
ImageIcon im = new ImageIcon("images/7224.jpg
c.add(new JLabel(im));
setSize(im.getIconWidth(),
>>i want the frame to be the size of the image.
c.add(new JLabel(new ImageIcon("x.jpg")));
pack();
c.add(new JLabel(new ImageIcon("x.jpg")));
pack();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)
ASKER
please refer to this url for question related to image
https://www.experts-exchange.com/questions/21858237/get-the-dimensions-on-the-image.html