• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Scale jpanel background image

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

Am new be in java and i wan to standarelize image as banner ,the image am using is big to get optimal quality,and i wan to create JPanel extended class to use it in the diffrent JFrames with this image in background.

so i must scale it i'v tried many examples but i down't know how exately i should use BufferedImage,and AffineTransform,and paintComponent.

can give an example please.



this one dosn't work
 
Rancher
Posts: 3265
30
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want the image to fill the entire background then you can check out Background Panel for example code. This uses dynamic painting and does not keep the width/height aspect ratio.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... and if you're using the JPanel only to display an image (that is, you're not adding any other components to it) you can user a JLabel instead, with a StretchIcon or ShrinkIcon. You can find those classes on the site linked by Rob.
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic