• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger
  • Frits Walraven

limit image to a certain amount of pixels

Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My java code below uses a JFRAME to display a image. The image is displaying but is taking up like 3000 pixels width. So I can see the entire image being display. I want my java code to display the image in a frame that is 500 by 500. The image has to fit within that frame.

Posts: 3163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. With Swing you override the paintComponent() method of a JPanel
2. A painting method should NOT do I/O. You want the method to be efficient since you can't control when the component will be repainted.
3. Read the Graphics API. There is a drawImage(…) method that allows you to specify the size of the image to be painted. So you would use the getWidth() and getHeight() methods of the JPanel to determine the image size.
Destroy anything that stands in your way. Except this tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
    Bookmark Topic Watch Topic
  • New Topic