Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Draw image to JPane in NetBeans

843806Nov 20 2008 — edited Nov 20 2008
I am developing a GUI in NetBeans that is for changing the settings.
one setting is a username and password.
once the user has inputed a username and password it needs to show a GIF image which is a loading kinda circle thing that goes around i don't have a problem with knowing when to show the image and start the request it is just the showing the image bit at the moment i have this code:
public ConfigGUI() {
	initComponents();
	center();
	System.out.println("Loading image");
	Graphics loginGraphics = loginPane.getGraphics();
	LoadImageApp image = new LoadImageApp("resources/strawberry.jpg");
	loginGraphics.drawImage(image.img, 1, 1, null);
	loginPane.repaint();
	loginPane.setVisible(true);
	System.out.println("Image loaded");
    }
    /* image class */

    public class LoadImageApp extends Component {

	BufferedImage img;

	//@Override
	public void paint(Graphics g) {
	    g.drawImage(img, 0, 0, null);
	}

	public LoadImageApp(String filename) {
	    try {
		img = ImageIO.read(new File(filename));
	    } catch (IOException e) {
		System.out.println("Failed to load image");
	    }

	}

	//@Override
	public Dimension getPreferredSize() {
	    if (img == null) {
		return new Dimension(100, 100);
	    } else {
		return new Dimension(img.getWidth(null), img.getHeight(null));
	    }
	}
    }
but it doesn't work.
am i using the right kind of components or do i need to use something other than a JPane?
and what code should i be using to output the image?

Scott.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 18 2008
Added on Nov 20 2008
2 comments
104 views