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

JScrollPane Problem

Justyn Dooley

Joined: Aug 03, 2009
Posts: 9
I am having a problem with a JScrollPane vertical scroll bar. This part of my program reads in questionnaire questions and responses from a file, and then places them on a screen with radio buttons for selection. Everything works fine other than the fact that on questionnaires in which the question and response panel is larger than the screen, the Vertical scroll bar starts scrolled to the bottom of the panel; I need it to start at the top of the page, always. I have tried setting the value of the scroll bar to zero, and setting the caret position of all the JTextAreas to zero, but to no avail. As a matter of fact, I printed out the value of the scroll bar when it was scrolled down, and it said it WAS zero. I really need some help, I cant figure this out.

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2447
Your code isn't executable to I can't see the problem.

1) never use updadeUI

2) make sure you create the GUI on the EDT.
Justyn Dooley

Joined: Aug 03, 2009
Posts: 9
It isn't executable due to the fact that I would have to upload a ton of resources for it to be. And what do you mean by EDT?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10817

What you need to do is post a sscce code so we can run it in our environment. Before posting any code, please do read the link to understand what SSCCE really means.

EDT means Event Dispatch Thread
To get an understanding of what Rob means by
2) make sure you create the GUI on the EDT.

check out this example. Notice the use of SwingUtilities in main() and the comments given there.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
I agree. Here's the link:
subject: JScrollPane Problem
It's not a secret anymore!