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

Show images in a JPanel

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
I'm really new in programming java and do need some help now.
How do I add some images (jpg-files, path out of a database) to a JPanel which extends a JScrollPane. The images should be resized to a thumbnail-size.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your best bet is to create JLabels inside your panel to apply the images to. So you code for that would be something like
[CODE]
ImageIcon myIcon = new ImageIcon("path\\to\\file.jpg");
JLabel myLabel = new JLabel(myIcon2);
[\CODE]
Now, where does myIcon2 come from?? Well, to resize the image to a thumbnail size you do something like this:
[CODE]
Image img = myIcon.getImage();
Image newimg = img.getScaledInstance(230, 310, Image.SCALE_SMOOTH);
myIcon2 = new ImageIcon(newimg);
[\CODE]
Your labels should be set to a size the same as what size your Images will be scaled to.
Hope that helps
Gregg
 
It runs on an internal combustion engine. This ad does not:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic