0

I am trying to get my program to display an image after it is dragged over, but I dont really have a good idea of how to do this.

Example: There is an image on your desktop, photo.jpg . You would take that, drag it over into a java JFrame, and the contents of that image (the photo iteself) would display.

From there I would like to be able to play with the size ability of the photo, but first step first, I dont know how to approach getting it to display in the JFrame. Any help would be greatly appreciated.

Lou Franco
  • 87,846
  • 14
  • 132
  • 192
Jim
  • 3,236
  • 8
  • 33
  • 43
  • Sorry for asking the obvious, but have you worked through the related Swing tutorials already? http://download.oracle.com/javase/tutorial/uiswing/dnd/index.html - edit: Hmm appears that's mostly (only?) related to in app Drag&Drop.. – Tim Oct 29 '10 at 19:45
  • I have, but I needed to understand how to do the part about the image more than the drag and drop part. – Jim Oct 29 '10 at 19:48

1 Answers1

2

Once you have the image (I didn't think you were asking about the drag-and-drop feature, if that was the part you were asking about, sorry.), you can either push the image into an ImageIcon and display it in a JLabel as described here

Or you can mess around with using Graphics#drawImage methods in paintComponent to draw Images. Something along the lines of (as a very basic example):

public void paintComponent(Graphics page)
{
    super.paintComponent(page);
    page.drawImage(img, 0, 0, null);
}

I give a more detailed example here.

Community
  • 1
  • 1
Reese Moore
  • 11,524
  • 3
  • 24
  • 32