File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JScrollPane Opens at Bottom by Default 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 Opens at Bottom by Default" Watch "JScrollPane Opens at Bottom by Default" New topic
Author

JScrollPane Opens at Bottom by Default

Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 210
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

Joined: Jun 19, 2012
Posts: 155
- 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

Joined: Feb 03, 2012
Posts: 210
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

Joined: May 03, 2008
Posts: 4531
    
    5

There isn't enough detail there for anyone to give an intelligent answer. That's where the SSCCE comes in.


luck, db
There are no new questions, but there may be new answers.
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 210
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Feb 03, 2012
Posts: 210
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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Feb 03, 2012
Posts: 210
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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Feb 03, 2012
Posts: 210
Ah, I hadn't thought of that since I am displaying a non-editable field. Now it makes sense.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: May 03, 2008
Posts: 4531
    
    5

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JScrollPane Opens at Bottom by Default