• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

limit image to a certain amount of pixels

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic