[nbusers] Re: Adding a .JPG image onto a label... does not display image...attached is my code

  • From: Edson Richter < >
  • To:
  • Subject: [nbusers] Re: Adding a .JPG image onto a label... does not display image...attached is my code
  • Date: Sun, 25 Nov 2012 23:52:00 -0200
  • Organization: Simkorp Inform├ítica Ltda


You probably can't use relative path - is your "jpg" file in the classpath?
Check this example (which works - I've used it recently to explain how to load resources using class loader):

http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/uiswing/examples/components/LabelDemoProject/src/components/LabelDemo.java

The explanation is available here:

http://docs.oracle.com/javase/tutorial/uiswing/components/label.html


Regards,

Edson


Em 24/11/2012 18:39, jarmenda escreveu:
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

  @SuppressWarnings("serial")
public class Exercise16_13 extends JFrame
  {
         private static JLabel label = new JLabel();
         private static ImageIcon image = new ImageIcon();
         private static JPanel panel = new JPanel();
        
         public Exercise16_13 (String title) {
                 super(title);
                                
                 String pic1 = "Flash Mob.jpg";
                
                 image = new ImageIcon(pic1);
                 label.setIcon(image);
                 label.setOpaque(true);
                 panel.add(label, BorderLayout.CENTER);
                 add(label);
         }
        
         public static void main(String[] args)
         {
                 JFrame frame = new JFrame();
frame.setSize(800, 600);
                 frame.setLocation(350, 50);
                 frame.setTitle("Slide Show");
                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 frame.setVisible( true );              
         }
  }









[nbusers] Adding a .JPG image onto a label... does not display image...attached is my code

jarmenda 11/24/2012

[nbusers] Re: Adding a .JPG image onto a label... does not display image...attached is my code

Edson Richter 11/26/2012

[nbusers] Thanks...Got it to work moved images below the jdk library in project

jarmenda 11/26/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close