Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: pictures wont load

  1. #1
    Member wolfgar's Avatar
    Join Date
    Oct 2009
    Location
    the middle of the woods
    Posts
    89
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default pictures wont load

    the method that deals with the pictures
    	private void jList1ListSelectionValueChanged(ListSelectionEvent event) {
    		String file = (String) shopItems.getSelectedValue();
    		int item = itemColorList.getSelectedIndex();
    		try {
    			URL picUrl = new URL(getCodeBase(),
    					"/Resources/TCC/pics/"+ file + "/");
    			Image pic = getImage(picUrl, (item+1)+ ".gif");
    			shopPictures.addPic(pic);
    			shopPictures.repaint();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}

    the shopPictures (PicturePanel) class
    package ernya;
     
    import java.awt.Graphics;
    import java.awt.Image;
     
    import javax.swing.JPanel;
     
    public class JPicturePanel extends JPanel {
    	Image pic = null;
    	private static final long serialVersionUID = 1L;
    	public JPicturePanel() {
    		initComponents(); 
    	}
    	private void initComponents() {
    		setSize(55, 55);
    	}
    	public void addPic(Image picture){
    		pic = picture;
    	}
    	public void paint(Graphics g){
    			g.drawImage(pic,0,0,this);
    	}
    }
    Programming: the art that fights back


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: pictures wont load

    Not fully sure if this is your problem but in your JPicturePanel I'd recommend overriding paintComponent rather than paint, and include a call to super.paintComponent. If you must use paint you should also include a super call to paint...
    public void paintComponent(Graphics g){
        super.paintComponent(g);
        if ( pic != null ){
            g.drawImage(pic, 0,0, this);
        }
    }

Similar Threads

  1. [SOLVED] I cant load the icon!!!!
    By chronoz13 in forum AWT / Java Swing
    Replies: 12
    Last Post: January 22nd, 2010, 03:52 AM
  2. quite small (make the changelog non-static, i.e. load its content from a file)
    By Abdallah in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: November 30th, 2009, 09:00 PM
  3. Arraylist Save and Load
    By frankycool in forum Collections and Generics
    Replies: 1
    Last Post: November 14th, 2009, 06:48 AM
  4. New Forum Avatar Pictures
    By JavaPF in forum The Cafe
    Replies: 0
    Last Post: February 14th, 2009, 12:15 PM
  5. How to animate pictures using JCreator?
    By bil_Imma in forum AWT / Java Swing
    Replies: 6
    Last Post: February 13th, 2009, 07:00 AM