This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying GIF/PNG image files in a Java Swing application

 
Salman Ahmed
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I tried searching for this topic through the archives but was unable to find a clear answer to my question, so please bear with me!)

I have this Java Swing application in which I need to display image files - GIF, PNG, and JPEG initially. TIFF (and optionally PDF) will be dealt with later on. The image files will be retrieved from a server application and even at their smallest size will be 640x480 pixels. All image manipulations (rotation, zoom in, zoom out, etc.) will be done by the server so all my application has to do is just display the retrieved image file.

What container or component should I use for this purpose? I would prefer to make this container/component be scrollable by putting it inside a JScrollPane . Or if there are other better ways to make such a displayed image scrollable, please let me know.

Lastly, would I need to use the Java 2D API to display/render the image files or would I need to look at some other API/library?

I am using Java 1.5 and Swing.

Thanks!
 
Brian Cole
Author
Ranch Hand
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Salman Ahmed:
I have this Java Swing application in which I need to display image files - GIF, PNG, and JPEG initially. TIFF (and optionally PDF) will be dealt with later on. The image files will be retrieved from a server application and even at their smallest size will be 640x480 pixels. All image manipulations (rotation, zoom in, zoom out, etc.) will be done by the server so all my application has to do is just display the retrieved image file.

What container or component should I use for this purpose? I would prefer to make this container/component be scrollable by putting it inside a JScrollPane .


ImageIcon is part of Swing and can handle GIF, PNG, and JPEG.

Showing an image in a scroll pane can be as easy as
new JScrollPane(new JLabel(new ImageIcon(...))).
 
Salman Ahmed
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I'll take a look at ImageIcon. Is it able to display images of size 1280x1024 or bigger?
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as your memory holds out.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic