• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Set scrollbar to top

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want my vertical scroll bar to initialize to the top but it always seems to start somewhere a few pixels from the bottom. I thought that this was the way to do it...

(html view is a JScrollPane)
htmlView.getVerticalScrollBar().setValue(0);
int val = htmlView.getVerticalScrollBar().getValue();
System.out.println("Value of scrollbar is " + val);

...but it always prints 0 while putting the scroller near the bottom. The docs seem to suggest that 0 is the value for "top". What did I do wrong? Thanks for any thoughts.
 
Rebecca Witmer
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, so I have been pondering this some more and I've come up with a lot of confusing data. Is there another way to do this scrollpane stuff? I am baffled. Maybe someone else won't be. Here's what I've come up with:

There are two scroll panes side-by-side in my gui. The left one has a tree of stuff you can click on to see metadata about it in the left side. Here's some code I have for setting up the panes (partially):



So that's at the beginning. When it first sets up the panels it always tells me:
Value of scrollbar is 0
Value of scrollbar is 0
That's right because the default is for there to be no vertical scrollbar unless the text stretches it out. Since there's no text yet, no scrollbar. Thus its value is 0.

Then I have added this to the code that runs when you click something on the left. I tried all _kinds_ of stuff to get it to behave:



But nothing works. The scroll bar stays not at the very bottom, but one or two pixels away, exactly at the bottom of the final character. Here's some output:

Value of scrollbar is 0 <---Initial values
Value of scrollbar is 0


Value of scrollbar before value changed is 0 <---After I clicked something
Value of scrollbar after value changed once is 0
Maximum is 295
Minimum is 0
Value of scrollbar after value changed twice is 0


Value of scrollbar before value changed is 252 <---The 2nd thing clicked
Value of scrollbar after value changed once is 0
Maximum is 295
Minimum is 0
Value of scrollbar after value changed twice is 0


Value of scrollbar before value changed is 86 <---Dragged the s.b. to the
Value of scrollbar after value changed once is 0 <---middle then clicked
Maximum is 295
Minimum is 0
Value of scrollbar after value changed twice is 0

If you take out setting the size of the JEditorPane to 295 and just let it figure out its own size it will say that the value of the scrollbar is 25 or 40 depending whether you add on another "Y" or not. That is, it sets the size and scroll bar value to match the amount of text.

I don't get why it wants to be at the bottom but at this point I am so baffled that I am willing to trash this idea and try another way. Is there another elegant way to do this?

Thanks,
Rebecca
 
Good night. Drive safely. Here's a tiny ad for the road:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic