• 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

Scrollbars wont appear on JPanel

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tryed just about every combination to get JScrollPane to work for me. I have created a JPanel and instantiated a ScrollPane with it, set preferred or default sizes, etc., but I cannot get a scroll pane on my image. Here is the code that I have, the main method is a simple instantiate and show from another class.

It gives me the picture fine, but no scroll bars! Note the hack that I attempted to add a JPanel that had a JScrollPane that had a JPanel. It doesnt work with just adding the JScrollPane to the contentpane
[ June 24, 2002: Message edited by: Prasant Jagannath ]
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ June 24, 2002: Message edited by: Dirk Schreckmann ]
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it should work if you add the JScrollPane directly to the content pane. your code looks ok. Are you extending JFrame or Frame? I suppose JFrame but check for that! I just had some strange behaviour in my GUI cause I forgot a J.
Maybe your image is just "not big enough"? The default is that JScrollPane doesn't show scroll bars if the viewport is totally visible. There is an option to change this behaviour. If you resize you frame to be smaller than the image, aren't the scrollbars showning up?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try loading the image into an ImageIcon, adding the ImageIcon to a JLabel, and then adding the JLabel to the JScrollPane. What you were doing wasn't working because JPanel has a preferred size of 0x0... and you didn't override your JPanel's getPreferredSize() method to return the size of the image...
 
After some pecan pie, you might want to cleanse your palatte with this 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