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

How do I add text to a scrollable JTextPane without scrolling the JScrollPane?

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using a JTextPane within a JScrollPane to display more text than the area provides. The controls live on a custom JDialog box and everything is fully initialized in the dialog's constructor. The scroll bars work and allow me to scroll around and view all of the text, but the problem is that the scrollbar is initialized at the lowest position. In other words, when my dialog appears the text field is scrolled down and displays the bottom of the block of text instead of the top.

The first thing I tried to do was set the vertical scrollbar's value to 0 after setting up the dialog, but the request is ignored. I thought this might be the result of the dialog being resized with "pack()" so I called this after pack() and it is still ignored.
As far as I can tell something happens after the dialog's constructor that changes this setting and wipes out mind, but I don't know what it is.




I rigged up the code to perform this command in one of my event handlers so that I could test it completely outside the initialization process and it worked fine, although if I check the current value I see that it's 176 instead of 0. That proves to me that something outside of my doing has moved it. Also, I have found that the size of the scrollpane changes from (410, 120) within the dialog's constructor to (420, 130). I thought this might be due to the appearance of the scrollbars but it is not. I changed the flags from the ..._SCROLLBAR_AS_NEEDED to the ..._SCROLLBAR_ALWAYS flags and the values continued to be as I see them. The min and max values always remain the same with min being 307 and max being 0.




At this point I am thinking that the only way to reposition my scrollbar to the top is to rig up some InvokeLater request, but I'd rather not have my text field appear to "bounce" after initialization.

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob Camick has a blog post about that. If you want more flexibility, you can find my additions to Rob's design here.
 
Steve Stevenson
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Darryl Burke wrote:Rob Camick has a blog post about that. If you want more flexibility, you can find my additions to Rob's design here.


Nice link! It answered my question and then it answered it again with another method that felt more secure!
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic