File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes GUI Scrollbar and file browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "GUI Scrollbar and file browser" Watch "GUI Scrollbar and file browser" New topic

GUI Scrollbar and file browser

Eric Crockett

Joined: Jan 24, 2005
Posts: 25
I am trying to get some GUI's working. I am currently using a JFrame and displaying an image. If the image is too big for the screen though, some of it gets cut off. I want to add a scrollbar (vertical for right now) so I can scroll down and see the rest of the pic. This is what I have so far:

class Picture extends JPanel
JFrame frame;
static Image image;

public void display()
Picture display = new Picture();

frame = new JFrame();
frame.getContentPane().add(BorderLayout.CENTER, display);

I am wondering if someone can explain how to use the scrollbar constructor(what all the int values do) and how to get it displayed on the side of the JFrame.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Swing often winds up with many containers nested in each other. Look into putting a ScrollPane on the content pane, then another JPanel on top of that to hold your screen. YOu can set ScrollPane properties to have vertical and/or horizontal scroll bars all the time or only when needed.

Warning: I don't do a lot of Swing so that may not be exactly the order to lay things together. Snoop around the JavaDoc or google for "scrollpane example" and I bet you'll find your way!

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Lionel Badiou
Ranch Hand

Joined: Jan 06, 2005
Posts: 140
Hello Eric,

You may find explanation and sample code for scrolling large picture at How to use scrollpane

Best regards,

Lionel Badiou
CodeFutures Software
I agree. Here's the link:
subject: GUI Scrollbar and file browser
It's not a secret anymore!