Help Loading ImageIcons [message #650834] |
Wed, 26 January 2011 18:27 |
Jorge Muralles Messages: 1 Registered: January 2011 |
Junior Member |
|
|
I am practicing some java and I need some help.
I amusing eclipse as my development environment.
I created a project called GUI (Graphical User Interface)
I am trying to put an image into an ImageIcon, and then add the icon to a label, then display the label with the image on a main window.
The image I want to display is called face.gif.
I use the following statements:
JFrame frame = new JFrame("Label - Icons - Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon icon = new ImageIcon("face.gif");
JLabel label1, label2, lable3;
label1 = new JLabel("Face Left", icon, SwingConstants.CENTER);
//set primary panel
JPanel panel = new JPanel();
panel.setBackground(Color.cyan);
panel.setPreferredSize(new Dimension(200,250));
panel.add(label1);
//Display main application
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
Where am I supposed to save the face.gif file and how can I get it to load into the ImageIcon.
Thank you.
|
|
|
Powered by
FUDForum. Page generated in 0.02411 seconds