• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JScrollPane doesn't work.

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there, I'm trying to get an image drawn from within a JPanels' paintComponent(Graphics g) method inside a JScrollPane.

The Drawer object (drawer) extends JPanel, and has size 800 by 800.
This has an image also 800 by 800.

The JFrame class is shown here:


But what happens is, I can only see top left corner of image, and there are no ScrollBars present to move the image around inside of the JScrollPane jsp object.

Can anyone help me?
Thanks
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you seem to be mixing the way to size:
null - setSize(..)
layoutManager - setPreferredSize(..)

(changed Drawer() to a JPanel with border)
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AMAZING, very fast too!!!

All I did was change drawer.setSize(...) to preferredSize(...)
And that worked

Don't know what the difference is, I'll look into it.

Thanks again!
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For those who came across this (as I did), wanted to post a follow-on solution. The code above works because there is no layout manager, which is uncommon for larger projects. Here's the same block using a common layout manager, MigLayout (not using any of its bells and whistles), and the SwingX implementation of JXPanel. Note that JXPanel can be easily replaced with JPanel, just remove the additional lines that tell the panel not to recalculate its size dynamically, but to enforce the scrollable region.

 
This will take every ounce of my mental strength! All for a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic