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 ]
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?
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...
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
keep an eye out for scorpions and black widows. But the tiny ads are safe.