Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JScrollPane Opens at Bottom by Default

 
Dennis Putnam
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a working JScrollPane but when the containing JFrame opens, the JScrollPane is at the bottom rather than the top. Shouldn't it be at the top by default? How do I get it to do that? TIA.
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- for better help sooner post an SSCCE,

- short, runnable, compilable, just about JFrame and JScrollPane,

- for this example to setSize for JFrame or setPreferredSize for JScrollPane, doesn't matter for SSCCE reasons
 
Dennis Putnam
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply but setting up an SSCCE to reproduce this is a lot of work. I am more interested in the answer to my question and I take it from your reply that it is yes, it should default to the top so I must have something wrong. Correct?
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't enough detail there for anyone to give an intelligent answer. That's where the SSCCE comes in.
 
Dennis Putnam
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you are understanding my question. I don't need detail at this point I just need to know what is supposed to happen. I can only see 2 possible answers. Either the JScrollPane positions itself at the top (this is the only one that really makes sense to me) or the bottom. Otherwise what determines where it initially positions itself when nothing is specified when created?
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's put it this way -- it doesn't work that way for me. My scroller shows up with the button at the top. So waving our hands about defaults isn't going to get us anywhere, we're going to have to look at the actual code.
 
Dennis Putnam
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait, I think I understand the confusion or rather my unclear explanation. I am not talking about the scroll widget (it is on the right as I only have vertical scrolling) but rather the initial position of the text and slider. I expected it to initially show the top of my text with the slider at the top as well. Instead, it initially shows the end of my text with the slider at the bottom. Hopefully this gets us on the same page. However, you mentioned "button", there is no "button" involved here just the widget with a slider and the up and down arrows at the top and bottom of the widget so that confuses me a bit.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> but rather the initial position of the text and slider.

if the scrollpane contains a textComponent and text, what you describe is normal behaviour.
you change this by adding this line (after adding any text)
textComponent.setCaretPosition(0);
 
Dennis Putnam
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. That is exactly what I was looking for. However, I find it an odd choice that the default is to position at the bottom initially.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I find it an odd choice that the default is to position at the bottom initially.

a text component does not know if a person is typing text or the program is adding text.
it just shows the caret position where the next character is to be typed.

what would be odd is typing text and you can't see the new text being added i.e. the top always shown.
 
Dennis Putnam
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I hadn't thought of that since I am displaying a non-editable field. Now it makes sense.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And that explains why my scroll pane opens with the slider (a.k.a. "button") at the top -- it contains a JTree and not a text component.
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis Putnam wrote:I expected it to initially show the top of my text with the slider at the top as well. Instead, it initially shows the end of my text with the slider at the bottom.

And only in your 4th post in this thread, which is the 7th post in the thread, is it now known to all that the JScrollPane houses a text component.

Now do you see why I said this?
There isn't enough detail there for anyone to give an intelligent answer.


This blog post by Rob Camick should be helpful: Text Area Scrolling
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic