Results 1 to 2 of 2
  1. #1
    aianta is offline Member
    Join Date
    Apr 2011
    Posts
    63
    Rep Power
    0

    Default Updating Images in swing

    So I have my code that displays a generated picture, and I made some text field where I can set some parameters and then see the effects on the picture. However I cant get the picture to update in the existing window. here's my code:
    Java Code:
    		if (event.getSource().equals(ytextField)){
    			imageY = new JLabel(new ImageIcon(va.getImageFromImageCubeFixedY(Integer.parseInt(ytextField.getText()))));
    			this.repaint();
    			System.out.println("Done! Y");
    		}
    		
    		if (event.getSource().equals(xtextField)){
    			imageX = new JLabel(new ImageIcon(va.getImageFromImageCubeFixedX(Integer.parseInt(xtextField.getText()))));
    			this.repaint();
    			System.out.println("Done! X");
    		}
    How do I go about updating those images, I tried using a setImage Icon but received a null pointer in the AWT event queue.

    And this is where I create the labels

    Java Code:
    		JLabel imageX = new JLabel(new ImageIcon(va.getImageFromImageCubeFixedX(1)));
    		imageX.setBounds(310, 11, 300, 300);
    		contentPane.add(imageX);
    		
    		
    		JLabel imageY = new JLabel(new ImageIcon(va.getImageFromImageCubeFixedY(1)));
    		imageY.setLocation(620, 11);
    		imageY.setSize(300, 300);
    		imageZ.setBounds(10, 11, 300, 300);
    		contentPane.add(imageY);
    Thanks in advance!

  2. #2
    aianta is offline Member
    Join Date
    Apr 2011
    Posts
    63
    Rep Power
    0

    Default Re: Updating Images in swing

    Never mind, declared variables when I didn't have to/

Similar Threads

  1. Swing frame not updating correctly
    By Heatryn in forum AWT / Swing
    Replies: 2
    Last Post: 07-05-2012, 05:24 PM
  2. Updating text displayed in a Swing Application
    By Fubarable in forum AWT / Swing
    Replies: 1
    Last Post: 09-16-2011, 06:31 AM
  3. Swing JLabel Updating (Threading)
    By Skezza in forum AWT / Swing
    Replies: 3
    Last Post: 07-27-2010, 04:43 PM
  4. Using Images in Swing
    By Chasingxsuns in forum New To Java
    Replies: 5
    Last Post: 08-01-2009, 01:22 AM
  5. Default Swing Images
    By Bubba_OH in forum New To Java
    Replies: 5
    Last Post: 10-10-2008, 04:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •