• 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

slight problem using JScrollPane

 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have an app that resizes the JFrame to fit the size of the image displayed in a JPanel. i decided to add a JScrollPane so it can display images that are larger than the screen(it cropped them). it works but the frame is a little too big and you cant see the horizontal scrollbar and only half of the vertical one. if i click the maximize button in the title bar, it displays correctly. how to correct this?

noticed i forgot to call super.paintComponent(g) but it worked anyway.
anyway adding that line had no effect.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you us an SSCCE?
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sure. the entire program is very short.
i know. all my variables can be private. i changed that.
sorry if its a little hard to read, i'm still mixing tabs and spaces.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure what pack() is doing when the preferred size is greater than the screen size, but on my system the horizontal/vertical sizes where both 12 pixels greater than the max.

I used the following to customize the size:



Also, there is no need to use a custom panel to display the image. I just added a JLabel to the scrollpane and then used:

 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok. thanks Rob. the first code you posted looks like what i need. i used pack because sometimes the image is small. your second code is interesting as well.

that fixed it thanks
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FYI for anyone who cares. i tried Rob's suggestion about not needing to call repaint(). it worked at first(when files were different size). but when i opened files the same size(my documents/my pictures/sample pictures), pack() didn't call repaint(). in fact pack didn't get called because the size was the same. so i needed to call repaint() after all.
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use a JLabel and reset the Icon there is no need to call repaint() because the setIcon() method calls repaint().
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'll try that next since it will be less code than using custom JPanel
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic